| Line Number |
../DebugInfoTest/example_mips_dbg.ll
|
Hit count |
Line Number |
../DebugInfoTest/example_mips.ll
|
Hit count |
| 1 |
//===- AttributorAttributes.cpp - Attributes for Attributor deduction -----===// |
--- |
1 |
//===- AttributorAttributes.cpp - Attributes for Attributor deduction -----===// |
--- |
| 2 |
// |
--- |
2 |
// |
--- |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
--- |
3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
--- |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
--- |
4 |
// See https://llvm.org/LICENSE.txt for license information. |
--- |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
--- |
5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
--- |
| 6 |
// |
--- |
6 |
// |
--- |
| 7 |
//===----------------------------------------------------------------------===// |
--- |
7 |
//===----------------------------------------------------------------------===// |
--- |
| 8 |
// |
--- |
8 |
// |
--- |
| 9 |
// See the Attributor.h file comment and the class descriptions in that file for |
--- |
9 |
// See the Attributor.h file comment and the class descriptions in that file for |
--- |
| 10 |
// more information. |
--- |
10 |
// more information. |
--- |
| 11 |
// |
--- |
11 |
// |
--- |
| 12 |
//===----------------------------------------------------------------------===// |
--- |
12 |
//===----------------------------------------------------------------------===// |
--- |
| 13 |
|
--- |
13 |
|
--- |
| 14 |
#include "llvm/Transforms/IPO/Attributor.h" |
--- |
14 |
#include "llvm/Transforms/IPO/Attributor.h" |
--- |
| 15 |
|
--- |
15 |
|
--- |
| 16 |
#include "llvm/ADT/APInt.h" |
--- |
16 |
#include "llvm/ADT/APInt.h" |
--- |
| 17 |
#include "llvm/ADT/ArrayRef.h" |
--- |
17 |
#include "llvm/ADT/ArrayRef.h" |
--- |
| 18 |
#include "llvm/ADT/DenseMapInfo.h" |
--- |
18 |
#include "llvm/ADT/DenseMapInfo.h" |
--- |
| 19 |
#include "llvm/ADT/MapVector.h" |
--- |
19 |
#include "llvm/ADT/MapVector.h" |
--- |
| 20 |
#include "llvm/ADT/SCCIterator.h" |
--- |
20 |
#include "llvm/ADT/SCCIterator.h" |
--- |
| 21 |
#include "llvm/ADT/STLExtras.h" |
--- |
21 |
#include "llvm/ADT/STLExtras.h" |
--- |
| 22 |
#include "llvm/ADT/SetOperations.h" |
--- |
22 |
#include "llvm/ADT/SetOperations.h" |
--- |
| 23 |
#include "llvm/ADT/SetVector.h" |
--- |
23 |
#include "llvm/ADT/SetVector.h" |
--- |
| 24 |
#include "llvm/ADT/SmallPtrSet.h" |
--- |
24 |
#include "llvm/ADT/SmallPtrSet.h" |
--- |
| 25 |
#include "llvm/ADT/SmallVector.h" |
--- |
25 |
#include "llvm/ADT/SmallVector.h" |
--- |
| 26 |
#include "llvm/ADT/Statistic.h" |
--- |
26 |
#include "llvm/ADT/Statistic.h" |
--- |
| 27 |
#include "llvm/ADT/StringExtras.h" |
--- |
27 |
#include "llvm/ADT/StringExtras.h" |
--- |
| 28 |
#include "llvm/Analysis/AliasAnalysis.h" |
--- |
28 |
#include "llvm/Analysis/AliasAnalysis.h" |
--- |
| 29 |
#include "llvm/Analysis/AssumeBundleQueries.h" |
--- |
29 |
#include "llvm/Analysis/AssumeBundleQueries.h" |
--- |
| 30 |
#include "llvm/Analysis/AssumptionCache.h" |
--- |
30 |
#include "llvm/Analysis/AssumptionCache.h" |
--- |
| 31 |
#include "llvm/Analysis/CaptureTracking.h" |
--- |
31 |
#include "llvm/Analysis/CaptureTracking.h" |
--- |
| 32 |
#include "llvm/Analysis/CycleAnalysis.h" |
--- |
32 |
#include "llvm/Analysis/CycleAnalysis.h" |
--- |
| 33 |
#include "llvm/Analysis/InstructionSimplify.h" |
--- |
33 |
#include "llvm/Analysis/InstructionSimplify.h" |
--- |
| 34 |
#include "llvm/Analysis/LazyValueInfo.h" |
--- |
34 |
#include "llvm/Analysis/LazyValueInfo.h" |
--- |
| 35 |
#include "llvm/Analysis/MemoryBuiltins.h" |
--- |
35 |
#include "llvm/Analysis/MemoryBuiltins.h" |
--- |
| 36 |
#include "llvm/Analysis/OptimizationRemarkEmitter.h" |
--- |
36 |
#include "llvm/Analysis/OptimizationRemarkEmitter.h" |
--- |
| 37 |
#include "llvm/Analysis/ScalarEvolution.h" |
--- |
37 |
#include "llvm/Analysis/ScalarEvolution.h" |
--- |
| 38 |
#include "llvm/Analysis/TargetTransformInfo.h" |
--- |
38 |
#include "llvm/Analysis/TargetTransformInfo.h" |
--- |
| 39 |
#include "llvm/Analysis/ValueTracking.h" |
--- |
39 |
#include "llvm/Analysis/ValueTracking.h" |
--- |
| 40 |
#include "llvm/IR/Argument.h" |
--- |
40 |
#include "llvm/IR/Argument.h" |
--- |
| 41 |
#include "llvm/IR/Assumptions.h" |
--- |
41 |
#include "llvm/IR/Assumptions.h" |
--- |
| 42 |
#include "llvm/IR/Attributes.h" |
--- |
42 |
#include "llvm/IR/Attributes.h" |
--- |
| 43 |
#include "llvm/IR/BasicBlock.h" |
--- |
43 |
#include "llvm/IR/BasicBlock.h" |
--- |
| 44 |
#include "llvm/IR/Constant.h" |
--- |
44 |
#include "llvm/IR/Constant.h" |
--- |
| 45 |
#include "llvm/IR/Constants.h" |
--- |
45 |
#include "llvm/IR/Constants.h" |
--- |
| 46 |
#include "llvm/IR/DataLayout.h" |
--- |
46 |
#include "llvm/IR/DataLayout.h" |
--- |
| 47 |
#include "llvm/IR/DerivedTypes.h" |
--- |
47 |
#include "llvm/IR/DerivedTypes.h" |
--- |
| 48 |
#include "llvm/IR/GlobalValue.h" |
--- |
48 |
#include "llvm/IR/GlobalValue.h" |
--- |
| 49 |
#include "llvm/IR/IRBuilder.h" |
--- |
49 |
#include "llvm/IR/IRBuilder.h" |
--- |
| 50 |
#include "llvm/IR/InlineAsm.h" |
--- |
50 |
#include "llvm/IR/InlineAsm.h" |
--- |
| 51 |
#include "llvm/IR/InstrTypes.h" |
--- |
51 |
#include "llvm/IR/InstrTypes.h" |
--- |
| 52 |
#include "llvm/IR/Instruction.h" |
--- |
52 |
#include "llvm/IR/Instruction.h" |
--- |
| 53 |
#include "llvm/IR/Instructions.h" |
--- |
53 |
#include "llvm/IR/Instructions.h" |
--- |
| 54 |
#include "llvm/IR/IntrinsicInst.h" |
--- |
54 |
#include "llvm/IR/IntrinsicInst.h" |
--- |
| 55 |
#include "llvm/IR/IntrinsicsAMDGPU.h" |
--- |
55 |
#include "llvm/IR/IntrinsicsAMDGPU.h" |
--- |
| 56 |
#include "llvm/IR/IntrinsicsNVPTX.h" |
--- |
56 |
#include "llvm/IR/IntrinsicsNVPTX.h" |
--- |
| 57 |
#include "llvm/IR/LLVMContext.h" |
--- |
57 |
#include "llvm/IR/LLVMContext.h" |
--- |
| 58 |
#include "llvm/IR/NoFolder.h" |
--- |
58 |
#include "llvm/IR/NoFolder.h" |
--- |
| 59 |
#include "llvm/IR/Value.h" |
--- |
59 |
#include "llvm/IR/Value.h" |
--- |
| 60 |
#include "llvm/IR/ValueHandle.h" |
--- |
60 |
#include "llvm/IR/ValueHandle.h" |
--- |
| 61 |
#include "llvm/Support/Alignment.h" |
--- |
61 |
#include "llvm/Support/Alignment.h" |
--- |
| 62 |
#include "llvm/Support/Casting.h" |
--- |
62 |
#include "llvm/Support/Casting.h" |
--- |
| 63 |
#include "llvm/Support/CommandLine.h" |
--- |
63 |
#include "llvm/Support/CommandLine.h" |
--- |
| 64 |
#include "llvm/Support/ErrorHandling.h" |
--- |
64 |
#include "llvm/Support/ErrorHandling.h" |
--- |
| 65 |
#include "llvm/Support/GraphWriter.h" |
--- |
65 |
#include "llvm/Support/GraphWriter.h" |
--- |
| 66 |
#include "llvm/Support/MathExtras.h" |
--- |
66 |
#include "llvm/Support/MathExtras.h" |
--- |
| 67 |
#include "llvm/Support/raw_ostream.h" |
--- |
67 |
#include "llvm/Support/raw_ostream.h" |
--- |
| 68 |
#include "llvm/Transforms/Utils/Local.h" |
--- |
68 |
#include "llvm/Transforms/Utils/Local.h" |
--- |
| 69 |
#include "llvm/Transforms/Utils/ValueMapper.h" |
--- |
69 |
#include "llvm/Transforms/Utils/ValueMapper.h" |
--- |
| 70 |
#include |
--- |
70 |
#include |
--- |
| 71 |
#include |
--- |
71 |
#include |
--- |
| 72 |
#include |
--- |
72 |
#include |
--- |
| 73 |
|
--- |
73 |
|
--- |
| 74 |
using namespace llvm; |
--- |
74 |
using namespace llvm; |
--- |
| 75 |
|
--- |
75 |
|
--- |
| 76 |
#define DEBUG_TYPE "attributor" |
--- |
76 |
#define DEBUG_TYPE "attributor" |
--- |
| 77 |
|
--- |
77 |
|
--- |
| 78 |
static cl::opt ManifestInternal( |
--- |
78 |
static cl::opt ManifestInternal( |
--- |
| 79 |
"attributor-manifest-internal", cl::Hidden, |
--- |
79 |
"attributor-manifest-internal", cl::Hidden, |
--- |
| 80 |
cl::desc("Manifest Attributor internal string attributes."), |
--- |
80 |
cl::desc("Manifest Attributor internal string attributes."), |
--- |
| 81 |
cl::init(false)); |
--- |
81 |
cl::init(false)); |
--- |
| 82 |
|
--- |
82 |
|
--- |
| 83 |
static cl::opt MaxHeapToStackSize("max-heap-to-stack-size", cl::init(128), |
--- |
83 |
static cl::opt MaxHeapToStackSize("max-heap-to-stack-size", cl::init(128), |
--- |
| 84 |
cl::Hidden); |
--- |
84 |
cl::Hidden); |
--- |
| 85 |
|
--- |
85 |
|
--- |
| 86 |
template <> |
--- |
86 |
template <> |
--- |
| 87 |
unsigned llvm::PotentialConstantIntValuesState::MaxPotentialValues = 0; |
--- |
87 |
unsigned llvm::PotentialConstantIntValuesState::MaxPotentialValues = 0; |
--- |
| 88 |
|
--- |
88 |
|
--- |
| 89 |
template <> unsigned llvm::PotentialLLVMValuesState::MaxPotentialValues = -1; |
--- |
89 |
template <> unsigned llvm::PotentialLLVMValuesState::MaxPotentialValues = -1; |
--- |
| 90 |
|
--- |
90 |
|
--- |
| 91 |
static cl::opt MaxPotentialValues( |
--- |
91 |
static cl::opt MaxPotentialValues( |
--- |
| 92 |
"attributor-max-potential-values", cl::Hidden, |
--- |
92 |
"attributor-max-potential-values", cl::Hidden, |
--- |
| 93 |
cl::desc("Maximum number of potential values to be " |
--- |
93 |
cl::desc("Maximum number of potential values to be " |
--- |
| 94 |
"tracked for each position."), |
--- |
94 |
"tracked for each position."), |
--- |
| 95 |
cl::location(llvm::PotentialConstantIntValuesState::MaxPotentialValues), |
--- |
95 |
cl::location(llvm::PotentialConstantIntValuesState::MaxPotentialValues), |
--- |
| 96 |
cl::init(7)); |
--- |
96 |
cl::init(7)); |
--- |
| 97 |
|
--- |
97 |
|
--- |
| 98 |
static cl::opt MaxPotentialValuesIterations( |
--- |
98 |
static cl::opt MaxPotentialValuesIterations( |
--- |
| 99 |
"attributor-max-potential-values-iterations", cl::Hidden, |
--- |
99 |
"attributor-max-potential-values-iterations", cl::Hidden, |
--- |
| 100 |
cl::desc( |
--- |
100 |
cl::desc( |
--- |
| 101 |
"Maximum number of iterations we keep dismantling potential values."), |
--- |
101 |
"Maximum number of iterations we keep dismantling potential values."), |
--- |
| 102 |
cl::init(64)); |
--- |
102 |
cl::init(64)); |
--- |
| 103 |
|
--- |
103 |
|
--- |
| 104 |
STATISTIC(NumAAs, "Number of abstract attributes created"); |
--- |
104 |
STATISTIC(NumAAs, "Number of abstract attributes created"); |
--- |
| 105 |
|
--- |
105 |
|
--- |
| 106 |
// Some helper macros to deal with statistics tracking. |
--- |
106 |
// Some helper macros to deal with statistics tracking. |
--- |
| 107 |
// |
--- |
107 |
// |
--- |
| 108 |
// Usage: |
--- |
108 |
// Usage: |
--- |
| 109 |
// For simple IR attribute tracking overload trackStatistics in the abstract |
--- |
109 |
// For simple IR attribute tracking overload trackStatistics in the abstract |
--- |
| 110 |
// attribute and choose the right STATS_DECLTRACK_********* macro, |
--- |
110 |
// attribute and choose the right STATS_DECLTRACK_********* macro, |
--- |
| 111 |
// e.g.,: |
--- |
111 |
// e.g.,: |
--- |
| 112 |
// void trackStatistics() const override { |
--- |
112 |
// void trackStatistics() const override { |
--- |
| 113 |
// STATS_DECLTRACK_ARG_ATTR(returned) |
--- |
113 |
// STATS_DECLTRACK_ARG_ATTR(returned) |
--- |
| 114 |
// } |
--- |
114 |
// } |
--- |
| 115 |
// If there is a single "increment" side one can use the macro |
--- |
115 |
// If there is a single "increment" side one can use the macro |
--- |
| 116 |
// STATS_DECLTRACK with a custom message. If there are multiple increment |
--- |
116 |
// STATS_DECLTRACK with a custom message. If there are multiple increment |
--- |
| 117 |
// sides, STATS_DECL and STATS_TRACK can also be used separately. |
--- |
117 |
// sides, STATS_DECL and STATS_TRACK can also be used separately. |
--- |
| 118 |
// |
--- |
118 |
// |
--- |
| 119 |
#define BUILD_STAT_MSG_IR_ATTR(TYPE, NAME) \ |
--- |
119 |
#define BUILD_STAT_MSG_IR_ATTR(TYPE, NAME) \ |
--- |
| 120 |
("Number of " #TYPE " marked '" #NAME "'") |
--- |
120 |
("Number of " #TYPE " marked '" #NAME "'") |
--- |
| 121 |
#define BUILD_STAT_NAME(NAME, TYPE) NumIR##TYPE##_##NAME |
--- |
121 |
#define BUILD_STAT_NAME(NAME, TYPE) NumIR##TYPE##_##NAME |
--- |
| 122 |
#define STATS_DECL_(NAME, MSG) STATISTIC(NAME, MSG); |
--- |
122 |
#define STATS_DECL_(NAME, MSG) STATISTIC(NAME, MSG); |
--- |
| 123 |
#define STATS_DECL(NAME, TYPE, MSG) \ |
--- |
123 |
#define STATS_DECL(NAME, TYPE, MSG) \ |
--- |
| 124 |
STATS_DECL_(BUILD_STAT_NAME(NAME, TYPE), MSG); |
--- |
124 |
STATS_DECL_(BUILD_STAT_NAME(NAME, TYPE), MSG); |
--- |
| 125 |
#define STATS_TRACK(NAME, TYPE) ++(BUILD_STAT_NAME(NAME, TYPE)); |
--- |
125 |
#define STATS_TRACK(NAME, TYPE) ++(BUILD_STAT_NAME(NAME, TYPE)); |
--- |
| 126 |
#define STATS_DECLTRACK(NAME, TYPE, MSG) \ |
--- |
126 |
#define STATS_DECLTRACK(NAME, TYPE, MSG) \ |
--- |
| 127 |
{ \ |
--- |
127 |
{ \ |
--- |
| 128 |
STATS_DECL(NAME, TYPE, MSG) \ |
--- |
128 |
STATS_DECL(NAME, TYPE, MSG) \ |
--- |
| 129 |
STATS_TRACK(NAME, TYPE) \ |
--- |
129 |
STATS_TRACK(NAME, TYPE) \ |
--- |
| 130 |
} |
--- |
130 |
} |
--- |
| 131 |
#define STATS_DECLTRACK_ARG_ATTR(NAME) \ |
--- |
131 |
#define STATS_DECLTRACK_ARG_ATTR(NAME) \ |
--- |
| 132 |
STATS_DECLTRACK(NAME, Arguments, BUILD_STAT_MSG_IR_ATTR(arguments, NAME)) |
--- |
132 |
STATS_DECLTRACK(NAME, Arguments, BUILD_STAT_MSG_IR_ATTR(arguments, NAME)) |
--- |
| 133 |
#define STATS_DECLTRACK_CSARG_ATTR(NAME) \ |
--- |
133 |
#define STATS_DECLTRACK_CSARG_ATTR(NAME) \ |
--- |
| 134 |
STATS_DECLTRACK(NAME, CSArguments, \ |
--- |
134 |
STATS_DECLTRACK(NAME, CSArguments, \ |
--- |
| 135 |
BUILD_STAT_MSG_IR_ATTR(call site arguments, NAME)) |
--- |
135 |
BUILD_STAT_MSG_IR_ATTR(call site arguments, NAME)) |
--- |
| 136 |
#define STATS_DECLTRACK_FN_ATTR(NAME) \ |
--- |
136 |
#define STATS_DECLTRACK_FN_ATTR(NAME) \ |
--- |
| 137 |
STATS_DECLTRACK(NAME, Function, BUILD_STAT_MSG_IR_ATTR(functions, NAME)) |
--- |
137 |
STATS_DECLTRACK(NAME, Function, BUILD_STAT_MSG_IR_ATTR(functions, NAME)) |
--- |
| 138 |
#define STATS_DECLTRACK_CS_ATTR(NAME) \ |
--- |
138 |
#define STATS_DECLTRACK_CS_ATTR(NAME) \ |
--- |
| 139 |
STATS_DECLTRACK(NAME, CS, BUILD_STAT_MSG_IR_ATTR(call site, NAME)) |
--- |
139 |
STATS_DECLTRACK(NAME, CS, BUILD_STAT_MSG_IR_ATTR(call site, NAME)) |
--- |
| 140 |
#define STATS_DECLTRACK_FNRET_ATTR(NAME) \ |
--- |
140 |
#define STATS_DECLTRACK_FNRET_ATTR(NAME) \ |
--- |
| 141 |
STATS_DECLTRACK(NAME, FunctionReturn, \ |
--- |
141 |
STATS_DECLTRACK(NAME, FunctionReturn, \ |
--- |
| 142 |
BUILD_STAT_MSG_IR_ATTR(function returns, NAME)) |
--- |
142 |
BUILD_STAT_MSG_IR_ATTR(function returns, NAME)) |
--- |
| 143 |
#define STATS_DECLTRACK_CSRET_ATTR(NAME) \ |
--- |
143 |
#define STATS_DECLTRACK_CSRET_ATTR(NAME) \ |
--- |
| 144 |
STATS_DECLTRACK(NAME, CSReturn, \ |
--- |
144 |
STATS_DECLTRACK(NAME, CSReturn, \ |
--- |
| 145 |
BUILD_STAT_MSG_IR_ATTR(call site returns, NAME)) |
--- |
145 |
BUILD_STAT_MSG_IR_ATTR(call site returns, NAME)) |
--- |
| 146 |
#define STATS_DECLTRACK_FLOATING_ATTR(NAME) \ |
--- |
146 |
#define STATS_DECLTRACK_FLOATING_ATTR(NAME) \ |
--- |
| 147 |
STATS_DECLTRACK(NAME, Floating, \ |
--- |
147 |
STATS_DECLTRACK(NAME, Floating, \ |
--- |
| 148 |
("Number of floating values known to be '" #NAME "'")) |
--- |
148 |
("Number of floating values known to be '" #NAME "'")) |
--- |
| 149 |
|
--- |
149 |
|
--- |
| 150 |
// Specialization of the operator<< for abstract attributes subclasses. This |
--- |
150 |
// Specialization of the operator<< for abstract attributes subclasses. This |
--- |
| 151 |
// disambiguates situations where multiple operators are applicable. |
--- |
151 |
// disambiguates situations where multiple operators are applicable. |
--- |
| 152 |
namespace llvm { |
--- |
152 |
namespace llvm { |
--- |
| 153 |
#define PIPE_OPERATOR(CLASS) \ |
--- |
153 |
#define PIPE_OPERATOR(CLASS) \ |
--- |
| 154 |
raw_ostream &operator<<(raw_ostream &OS, const CLASS &AA) { \ |
--- |
154 |
raw_ostream &operator<<(raw_ostream &OS, const CLASS &AA) { \ |
--- |
| 155 |
return OS << static_cast(AA); \ |
--- |
155 |
return OS << static_cast(AA); \ |
--- |
| 156 |
} |
--- |
156 |
} |
--- |
| 157 |
|
--- |
157 |
|
--- |
| 158 |
PIPE_OPERATOR(AAIsDead) |
0 |
158 |
PIPE_OPERATOR(AAIsDead) |
0 |
| 159 |
PIPE_OPERATOR(AANoUnwind) |
0 |
159 |
PIPE_OPERATOR(AANoUnwind) |
0 |
| 160 |
PIPE_OPERATOR(AANoSync) |
0 |
160 |
PIPE_OPERATOR(AANoSync) |
0 |
| 161 |
PIPE_OPERATOR(AANoRecurse) |
0 |
161 |
PIPE_OPERATOR(AANoRecurse) |
0 |
| 162 |
PIPE_OPERATOR(AANonConvergent) |
0 |
162 |
PIPE_OPERATOR(AANonConvergent) |
0 |
| 163 |
PIPE_OPERATOR(AAWillReturn) |
0 |
163 |
PIPE_OPERATOR(AAWillReturn) |
0 |
| 164 |
PIPE_OPERATOR(AANoReturn) |
0 |
164 |
PIPE_OPERATOR(AANoReturn) |
0 |
| 165 |
PIPE_OPERATOR(AANonNull) |
0 |
165 |
PIPE_OPERATOR(AANonNull) |
0 |
| 166 |
PIPE_OPERATOR(AAMustProgress) |
0 |
166 |
PIPE_OPERATOR(AAMustProgress) |
0 |
| 167 |
PIPE_OPERATOR(AANoAlias) |
0 |
167 |
PIPE_OPERATOR(AANoAlias) |
0 |
| 168 |
PIPE_OPERATOR(AADereferenceable) |
0 |
168 |
PIPE_OPERATOR(AADereferenceable) |
0 |
| 169 |
PIPE_OPERATOR(AAAlign) |
0 |
169 |
PIPE_OPERATOR(AAAlign) |
0 |
| 170 |
PIPE_OPERATOR(AAInstanceInfo) |
0 |
170 |
PIPE_OPERATOR(AAInstanceInfo) |
0 |
| 171 |
PIPE_OPERATOR(AANoCapture) |
0 |
171 |
PIPE_OPERATOR(AANoCapture) |
0 |
| 172 |
PIPE_OPERATOR(AAValueSimplify) |
0 |
172 |
PIPE_OPERATOR(AAValueSimplify) |
0 |
| 173 |
PIPE_OPERATOR(AANoFree) |
0 |
173 |
PIPE_OPERATOR(AANoFree) |
0 |
| 174 |
PIPE_OPERATOR(AAHeapToStack) |
0 |
174 |
PIPE_OPERATOR(AAHeapToStack) |
0 |
| 175 |
PIPE_OPERATOR(AAIntraFnReachability) |
0 |
175 |
PIPE_OPERATOR(AAIntraFnReachability) |
0 |
| 176 |
PIPE_OPERATOR(AAMemoryBehavior) |
0 |
176 |
PIPE_OPERATOR(AAMemoryBehavior) |
0 |
| 177 |
PIPE_OPERATOR(AAMemoryLocation) |
0 |
177 |
PIPE_OPERATOR(AAMemoryLocation) |
0 |
| 178 |
PIPE_OPERATOR(AAValueConstantRange) |
0 |
178 |
PIPE_OPERATOR(AAValueConstantRange) |
0 |
| 179 |
PIPE_OPERATOR(AAPrivatizablePtr) |
0 |
179 |
PIPE_OPERATOR(AAPrivatizablePtr) |
0 |
| 180 |
PIPE_OPERATOR(AAUndefinedBehavior) |
0 |
180 |
PIPE_OPERATOR(AAUndefinedBehavior) |
0 |
| 181 |
PIPE_OPERATOR(AAPotentialConstantValues) |
0 |
181 |
PIPE_OPERATOR(AAPotentialConstantValues) |
0 |
| 182 |
PIPE_OPERATOR(AAPotentialValues) |
0 |
182 |
PIPE_OPERATOR(AAPotentialValues) |
0 |
| 183 |
PIPE_OPERATOR(AANoUndef) |
0 |
183 |
PIPE_OPERATOR(AANoUndef) |
0 |
| 184 |
PIPE_OPERATOR(AANoFPClass) |
0 |
184 |
PIPE_OPERATOR(AANoFPClass) |
0 |
| 185 |
PIPE_OPERATOR(AACallEdges) |
0 |
185 |
PIPE_OPERATOR(AACallEdges) |
0 |
| 186 |
PIPE_OPERATOR(AAInterFnReachability) |
0 |
186 |
PIPE_OPERATOR(AAInterFnReachability) |
0 |
| 187 |
PIPE_OPERATOR(AAPointerInfo) |
0 |
187 |
PIPE_OPERATOR(AAPointerInfo) |
0 |
| 188 |
PIPE_OPERATOR(AAAssumptionInfo) |
0 |
188 |
PIPE_OPERATOR(AAAssumptionInfo) |
0 |
| 189 |
PIPE_OPERATOR(AAUnderlyingObjects) |
0 |
189 |
PIPE_OPERATOR(AAUnderlyingObjects) |
0 |
| 190 |
PIPE_OPERATOR(AAAddressSpace) |
0 |
190 |
PIPE_OPERATOR(AAAddressSpace) |
0 |
| 191 |
|
--- |
191 |
|
--- |
| 192 |
#undef PIPE_OPERATOR |
--- |
192 |
#undef PIPE_OPERATOR |
--- |
| 193 |
|
--- |
193 |
|
--- |
| 194 |
template <> |
--- |
194 |
template <> |
--- |
| 195 |
ChangeStatus clampStateAndIndicateChange(DerefState &S, |
0 |
195 |
ChangeStatus clampStateAndIndicateChange(DerefState &S, |
0 |
| 196 |
const DerefState &R) { |
--- |
196 |
const DerefState &R) { |
--- |
| 197 |
ChangeStatus CS0 = |
--- |
197 |
ChangeStatus CS0 = |
--- |
| 198 |
clampStateAndIndicateChange(S.DerefBytesState, R.DerefBytesState); |
0 |
198 |
clampStateAndIndicateChange(S.DerefBytesState, R.DerefBytesState); |
0 |
| 199 |
ChangeStatus CS1 = clampStateAndIndicateChange(S.GlobalState, R.GlobalState); |
0 |
199 |
ChangeStatus CS1 = clampStateAndIndicateChange(S.GlobalState, R.GlobalState); |
0 |
| 200 |
return CS0 | CS1; |
0 |
200 |
return CS0 | CS1; |
0 |
| 201 |
} |
--- |
201 |
} |
--- |
| 202 |
|
--- |
202 |
|
--- |
| 203 |
} // namespace llvm |
--- |
203 |
} // namespace llvm |
--- |
| 204 |
|
--- |
204 |
|
--- |
| 205 |
static bool mayBeInCycle(const CycleInfo *CI, const Instruction *I, |
0 |
205 |
static bool mayBeInCycle(const CycleInfo *CI, const Instruction *I, |
0 |
| 206 |
bool HeaderOnly, Cycle **CPtr = nullptr) { |
--- |
206 |
bool HeaderOnly, Cycle **CPtr = nullptr) { |
--- |
| 207 |
if (!CI) |
0 |
207 |
if (!CI) |
0 |
| 208 |
return true; |
0 |
208 |
return true; |
0 |
| 209 |
auto *BB = I->getParent(); |
0 |
209 |
auto *BB = I->getParent(); |
0 |
| 210 |
auto *C = CI->getCycle(BB); |
0 |
210 |
auto *C = CI->getCycle(BB); |
0 |
| 211 |
if (!C) |
0 |
211 |
if (!C) |
0 |
| 212 |
return false; |
0 |
212 |
return false; |
0 |
| 213 |
if (CPtr) |
0 |
213 |
if (CPtr) |
0 |
| 214 |
*CPtr = C; |
0 |
214 |
*CPtr = C; |
0 |
| 215 |
return !HeaderOnly || BB == C->getHeader(); |
0 |
215 |
return !HeaderOnly || BB == C->getHeader(); |
0 |
| 216 |
} |
--- |
216 |
} |
--- |
| 217 |
|
--- |
217 |
|
--- |
| 218 |
/// Checks if a type could have padding bytes. |
--- |
218 |
/// Checks if a type could have padding bytes. |
--- |
| 219 |
static bool isDenselyPacked(Type *Ty, const DataLayout &DL) { |
0 |
219 |
static bool isDenselyPacked(Type *Ty, const DataLayout &DL) { |
0 |
| 220 |
// There is no size information, so be conservative. |
--- |
220 |
// There is no size information, so be conservative. |
--- |
| 221 |
if (!Ty->isSized()) |
0 |
221 |
if (!Ty->isSized()) |
0 |
| 222 |
return false; |
0 |
222 |
return false; |
0 |
| 223 |
|
--- |
223 |
|
--- |
| 224 |
// If the alloc size is not equal to the storage size, then there are padding |
--- |
224 |
// If the alloc size is not equal to the storage size, then there are padding |
--- |
| 225 |
// bytes. For x86_fp80 on x86-64, size: 80 alloc size: 128. |
--- |
225 |
// bytes. For x86_fp80 on x86-64, size: 80 alloc size: 128. |
--- |
| 226 |
if (DL.getTypeSizeInBits(Ty) != DL.getTypeAllocSizeInBits(Ty)) |
0 |
226 |
if (DL.getTypeSizeInBits(Ty) != DL.getTypeAllocSizeInBits(Ty)) |
0 |
| 227 |
return false; |
0 |
227 |
return false; |
0 |
| 228 |
|
--- |
228 |
|
--- |
| 229 |
// FIXME: This isn't the right way to check for padding in vectors with |
--- |
229 |
// FIXME: This isn't the right way to check for padding in vectors with |
--- |
| 230 |
// non-byte-size elements. |
--- |
230 |
// non-byte-size elements. |
--- |
| 231 |
if (VectorType *SeqTy = dyn_cast(Ty)) |
0 |
231 |
if (VectorType *SeqTy = dyn_cast(Ty)) |
0 |
| 232 |
return isDenselyPacked(SeqTy->getElementType(), DL); |
0 |
232 |
return isDenselyPacked(SeqTy->getElementType(), DL); |
0 |
| 233 |
|
--- |
233 |
|
--- |
| 234 |
// For array types, check for padding within members. |
--- |
234 |
// For array types, check for padding within members. |
--- |
| 235 |
if (ArrayType *SeqTy = dyn_cast(Ty)) |
0 |
235 |
if (ArrayType *SeqTy = dyn_cast(Ty)) |
0 |
| 236 |
return isDenselyPacked(SeqTy->getElementType(), DL); |
0 |
236 |
return isDenselyPacked(SeqTy->getElementType(), DL); |
0 |
| 237 |
|
--- |
237 |
|
--- |
| 238 |
if (!isa(Ty)) |
0 |
238 |
if (!isa(Ty)) |
0 |
| 239 |
return true; |
0 |
239 |
return true; |
0 |
| 240 |
|
--- |
240 |
|
--- |
| 241 |
// Check for padding within and between elements of a struct. |
--- |
241 |
// Check for padding within and between elements of a struct. |
--- |
| 242 |
StructType *StructTy = cast(Ty); |
0 |
242 |
StructType *StructTy = cast(Ty); |
0 |
| 243 |
const StructLayout *Layout = DL.getStructLayout(StructTy); |
0 |
243 |
const StructLayout *Layout = DL.getStructLayout(StructTy); |
0 |
| 244 |
uint64_t StartPos = 0; |
0 |
244 |
uint64_t StartPos = 0; |
0 |
| 245 |
for (unsigned I = 0, E = StructTy->getNumElements(); I < E; ++I) { |
0 |
245 |
for (unsigned I = 0, E = StructTy->getNumElements(); I < E; ++I) { |
0 |
| 246 |
Type *ElTy = StructTy->getElementType(I); |
0 |
246 |
Type *ElTy = StructTy->getElementType(I); |
0 |
| 247 |
if (!isDenselyPacked(ElTy, DL)) |
0 |
247 |
if (!isDenselyPacked(ElTy, DL)) |
0 |
| 248 |
return false; |
0 |
248 |
return false; |
0 |
| 249 |
if (StartPos != Layout->getElementOffsetInBits(I)) |
0 |
249 |
if (StartPos != Layout->getElementOffsetInBits(I)) |
0 |
| 250 |
return false; |
0 |
250 |
return false; |
0 |
| 251 |
StartPos += DL.getTypeAllocSizeInBits(ElTy); |
0 |
251 |
StartPos += DL.getTypeAllocSizeInBits(ElTy); |
0 |
| 252 |
} |
--- |
252 |
} |
--- |
| 253 |
|
--- |
253 |
|
--- |
| 254 |
return true; |
0 |
254 |
return true; |
0 |
| 255 |
} |
--- |
255 |
} |
--- |
| 256 |
|
--- |
256 |
|
--- |
| 257 |
/// Get pointer operand of memory accessing instruction. If \p I is |
--- |
257 |
/// Get pointer operand of memory accessing instruction. If \p I is |
--- |
| 258 |
/// not a memory accessing instruction, return nullptr. If \p AllowVolatile, |
--- |
258 |
/// not a memory accessing instruction, return nullptr. If \p AllowVolatile, |
--- |
| 259 |
/// is set to false and the instruction is volatile, return nullptr. |
--- |
259 |
/// is set to false and the instruction is volatile, return nullptr. |
--- |
| 260 |
static const Value *getPointerOperand(const Instruction *I, |
0 |
260 |
static const Value *getPointerOperand(const Instruction *I, |
0 |
| 261 |
bool AllowVolatile) { |
--- |
261 |
bool AllowVolatile) { |
--- |
| 262 |
if (!AllowVolatile && I->isVolatile()) |
0 |
262 |
if (!AllowVolatile && I->isVolatile()) |
0 |
| 263 |
return nullptr; |
0 |
263 |
return nullptr; |
0 |
| 264 |
|
--- |
264 |
|
--- |
| 265 |
if (auto *LI = dyn_cast(I)) { |
0 |
265 |
if (auto *LI = dyn_cast(I)) { |
0 |
| 266 |
return LI->getPointerOperand(); |
0 |
266 |
return LI->getPointerOperand(); |
0 |
| 267 |
} |
--- |
267 |
} |
--- |
| 268 |
|
--- |
268 |
|
--- |
| 269 |
if (auto *SI = dyn_cast(I)) { |
0 |
269 |
if (auto *SI = dyn_cast(I)) { |
0 |
| 270 |
return SI->getPointerOperand(); |
0 |
270 |
return SI->getPointerOperand(); |
0 |
| 271 |
} |
--- |
271 |
} |
--- |
| 272 |
|
--- |
272 |
|
--- |
| 273 |
if (auto *CXI = dyn_cast(I)) { |
0 |
273 |
if (auto *CXI = dyn_cast(I)) { |
0 |
| 274 |
return CXI->getPointerOperand(); |
0 |
274 |
return CXI->getPointerOperand(); |
0 |
| 275 |
} |
--- |
275 |
} |
--- |
| 276 |
|
--- |
276 |
|
--- |
| 277 |
if (auto *RMWI = dyn_cast(I)) { |
0 |
277 |
if (auto *RMWI = dyn_cast(I)) { |
0 |
| 278 |
return RMWI->getPointerOperand(); |
0 |
278 |
return RMWI->getPointerOperand(); |
0 |
| 279 |
} |
--- |
279 |
} |
--- |
| 280 |
|
--- |
280 |
|
--- |
| 281 |
return nullptr; |
0 |
281 |
return nullptr; |
0 |
| 282 |
} |
--- |
282 |
} |
--- |
| 283 |
|
--- |
283 |
|
--- |
| 284 |
/// Helper function to create a pointer of type \p ResTy, based on \p Ptr, and |
--- |
284 |
/// Helper function to create a pointer of type \p ResTy, based on \p Ptr, and |
--- |
| 285 |
/// advanced by \p Offset bytes. To aid later analysis the method tries to build |
--- |
285 |
/// advanced by \p Offset bytes. To aid later analysis the method tries to build |
--- |
| 286 |
/// getelement pointer instructions that traverse the natural type of \p Ptr if |
--- |
286 |
/// getelement pointer instructions that traverse the natural type of \p Ptr if |
--- |
| 287 |
/// possible. If that fails, the remaining offset is adjusted byte-wise, hence |
--- |
287 |
/// possible. If that fails, the remaining offset is adjusted byte-wise, hence |
--- |
| 288 |
/// through a cast to i8*. |
--- |
288 |
/// through a cast to i8*. |
--- |
| 289 |
/// |
--- |
289 |
/// |
--- |
| 290 |
/// TODO: This could probably live somewhere more prominantly if it doesn't |
--- |
290 |
/// TODO: This could probably live somewhere more prominantly if it doesn't |
--- |
| 291 |
/// already exist. |
--- |
291 |
/// already exist. |
--- |
| 292 |
static Value *constructPointer(Type *ResTy, Type *PtrElemTy, Value *Ptr, |
0 |
292 |
static Value *constructPointer(Type *ResTy, Type *PtrElemTy, Value *Ptr, |
0 |
| 293 |
int64_t Offset, IRBuilder &IRB, |
--- |
293 |
int64_t Offset, IRBuilder &IRB, |
--- |
| 294 |
const DataLayout &DL) { |
--- |
294 |
const DataLayout &DL) { |
--- |
| 295 |
assert(Offset >= 0 && "Negative offset not supported yet!"); |
0 |
295 |
assert(Offset >= 0 && "Negative offset not supported yet!"); |
0 |
| 296 |
LLVM_DEBUG(dbgs() << "Construct pointer: " << *Ptr << " + " << Offset |
0 |
296 |
LLVM_DEBUG(dbgs() << "Construct pointer: " << *Ptr << " + " << Offset |
0 |
| 297 |
<< "-bytes as " << *ResTy << "\n"); |
--- |
297 |
<< "-bytes as " << *ResTy << "\n"); |
--- |
| 298 |
|
--- |
298 |
|
--- |
| 299 |
if (Offset) { |
0 |
299 |
if (Offset) { |
0 |
| 300 |
Type *Ty = PtrElemTy; |
0 |
300 |
Type *Ty = PtrElemTy; |
0 |
| 301 |
APInt IntOffset(DL.getIndexTypeSizeInBits(Ptr->getType()), Offset); |
0 |
301 |
APInt IntOffset(DL.getIndexTypeSizeInBits(Ptr->getType()), Offset); |
0 |
| 302 |
SmallVector IntIndices = DL.getGEPIndicesForOffset(Ty, IntOffset); |
0 |
302 |
SmallVector IntIndices = DL.getGEPIndicesForOffset(Ty, IntOffset); |
0 |
| 303 |
|
--- |
303 |
|
--- |
| 304 |
SmallVector ValIndices; |
0 |
304 |
SmallVector ValIndices; |
0 |
| 305 |
std::string GEPName = Ptr->getName().str(); |
0 |
305 |
std::string GEPName = Ptr->getName().str(); |
0 |
| 306 |
for (const APInt &Index : IntIndices) { |
0 |
306 |
for (const APInt &Index : IntIndices) { |
0 |
| 307 |
ValIndices.push_back(IRB.getInt(Index)); |
0 |
307 |
ValIndices.push_back(IRB.getInt(Index)); |
0 |
| 308 |
GEPName += "." + std::to_string(Index.getZExtValue()); |
0 |
308 |
GEPName += "." + std::to_string(Index.getZExtValue()); |
0 |
| 309 |
} |
--- |
309 |
} |
--- |
| 310 |
|
--- |
310 |
|
--- |
| 311 |
// Create a GEP for the indices collected above. |
--- |
311 |
// Create a GEP for the indices collected above. |
--- |
| 312 |
Ptr = IRB.CreateGEP(PtrElemTy, Ptr, ValIndices, GEPName); |
0 |
312 |
Ptr = IRB.CreateGEP(PtrElemTy, Ptr, ValIndices, GEPName); |
0 |
| 313 |
|
--- |
313 |
|
--- |
| 314 |
// If an offset is left we use byte-wise adjustment. |
--- |
314 |
// If an offset is left we use byte-wise adjustment. |
--- |
| 315 |
if (IntOffset != 0) { |
0 |
315 |
if (IntOffset != 0) { |
0 |
| 316 |
Ptr = IRB.CreateBitCast(Ptr, IRB.getInt8PtrTy()); |
0 |
316 |
Ptr = IRB.CreateBitCast(Ptr, IRB.getInt8PtrTy()); |
0 |
| 317 |
Ptr = IRB.CreateGEP(IRB.getInt8Ty(), Ptr, IRB.getInt(IntOffset), |
0 |
317 |
Ptr = IRB.CreateGEP(IRB.getInt8Ty(), Ptr, IRB.getInt(IntOffset), |
0 |
| 318 |
GEPName + ".b" + Twine(IntOffset.getZExtValue())); |
0 |
318 |
GEPName + ".b" + Twine(IntOffset.getZExtValue())); |
0 |
| 319 |
} |
--- |
319 |
} |
--- |
| 320 |
} |
0 |
320 |
} |
0 |
| 321 |
|
--- |
321 |
|
--- |
| 322 |
// Ensure the result has the requested type. |
--- |
322 |
// Ensure the result has the requested type. |
--- |
| 323 |
Ptr = IRB.CreatePointerBitCastOrAddrSpaceCast(Ptr, ResTy, |
0 |
323 |
Ptr = IRB.CreatePointerBitCastOrAddrSpaceCast(Ptr, ResTy, |
0 |
| 324 |
Ptr->getName() + ".cast"); |
0 |
324 |
Ptr->getName() + ".cast"); |
0 |
| 325 |
|
--- |
325 |
|
--- |
| 326 |
LLVM_DEBUG(dbgs() << "Constructed pointer: " << *Ptr << "\n"); |
0 |
326 |
LLVM_DEBUG(dbgs() << "Constructed pointer: " << *Ptr << "\n"); |
0 |
| 327 |
return Ptr; |
0 |
327 |
return Ptr; |
0 |
| 328 |
} |
--- |
328 |
} |
--- |
| 329 |
|
--- |
329 |
|
--- |
| 330 |
static const Value * |
--- |
330 |
static const Value * |
--- |
| 331 |
stripAndAccumulateOffsets(Attributor &A, const AbstractAttribute &QueryingAA, |
0 |
331 |
stripAndAccumulateOffsets(Attributor &A, const AbstractAttribute &QueryingAA, |
0 |
| 332 |
const Value *Val, const DataLayout &DL, APInt &Offset, |
--- |
332 |
const Value *Val, const DataLayout &DL, APInt &Offset, |
--- |
| 333 |
bool GetMinOffset, bool AllowNonInbounds, |
--- |
333 |
bool GetMinOffset, bool AllowNonInbounds, |
--- |
| 334 |
bool UseAssumed = false) { |
--- |
334 |
bool UseAssumed = false) { |
--- |
| 335 |
|
--- |
335 |
|
--- |
| 336 |
auto AttributorAnalysis = [&](Value &V, APInt &ROffset) -> bool { |
0 |
336 |
auto AttributorAnalysis = [&](Value &V, APInt &ROffset) -> bool { |
0 |
| 337 |
const IRPosition &Pos = IRPosition::value(V); |
0 |
337 |
const IRPosition &Pos = IRPosition::value(V); |
0 |
| 338 |
// Only track dependence if we are going to use the assumed info. |
--- |
338 |
// Only track dependence if we are going to use the assumed info. |
--- |
| 339 |
const AAValueConstantRange *ValueConstantRangeAA = |
--- |
339 |
const AAValueConstantRange *ValueConstantRangeAA = |
--- |
| 340 |
A.getAAFor(QueryingAA, Pos, |
0 |
340 |
A.getAAFor(QueryingAA, Pos, |
0 |
| 341 |
UseAssumed ? DepClassTy::OPTIONAL |
0 |
341 |
UseAssumed ? DepClassTy::OPTIONAL |
0 |
| 342 |
: DepClassTy::NONE); |
--- |
342 |
: DepClassTy::NONE); |
--- |
| 343 |
if (!ValueConstantRangeAA) |
0 |
343 |
if (!ValueConstantRangeAA) |
0 |
| 344 |
return false; |
0 |
344 |
return false; |
0 |
| 345 |
ConstantRange Range = UseAssumed ? ValueConstantRangeAA->getAssumed() |
0 |
345 |
ConstantRange Range = UseAssumed ? ValueConstantRangeAA->getAssumed() |
0 |
| 346 |
: ValueConstantRangeAA->getKnown(); |
0 |
346 |
: ValueConstantRangeAA->getKnown(); |
0 |
| 347 |
if (Range.isFullSet()) |
0 |
347 |
if (Range.isFullSet()) |
0 |
| 348 |
return false; |
0 |
348 |
return false; |
0 |
| 349 |
|
--- |
349 |
|
--- |
| 350 |
// We can only use the lower part of the range because the upper part can |
--- |
350 |
// We can only use the lower part of the range because the upper part can |
--- |
| 351 |
// be higher than what the value can really be. |
--- |
351 |
// be higher than what the value can really be. |
--- |
| 352 |
if (GetMinOffset) |
0 |
352 |
if (GetMinOffset) |
0 |
| 353 |
ROffset = Range.getSignedMin(); |
0 |
353 |
ROffset = Range.getSignedMin(); |
0 |
| 354 |
else |
--- |
354 |
else |
--- |
| 355 |
ROffset = Range.getSignedMax(); |
0 |
355 |
ROffset = Range.getSignedMax(); |
0 |
| 356 |
return true; |
0 |
356 |
return true; |
0 |
| 357 |
}; |
0 |
357 |
}; |
0 |
| 358 |
|
--- |
358 |
|
--- |
| 359 |
return Val->stripAndAccumulateConstantOffsets(DL, Offset, AllowNonInbounds, |
0 |
359 |
return Val->stripAndAccumulateConstantOffsets(DL, Offset, AllowNonInbounds, |
0 |
| 360 |
/* AllowInvariant */ true, |
--- |
360 |
/* AllowInvariant */ true, |
--- |
| 361 |
AttributorAnalysis); |
0 |
361 |
AttributorAnalysis); |
0 |
| 362 |
} |
--- |
362 |
} |
--- |
| 363 |
|
--- |
363 |
|
--- |
| 364 |
static const Value * |
--- |
364 |
static const Value * |
--- |
| 365 |
getMinimalBaseOfPointer(Attributor &A, const AbstractAttribute &QueryingAA, |
0 |
365 |
getMinimalBaseOfPointer(Attributor &A, const AbstractAttribute &QueryingAA, |
0 |
| 366 |
const Value *Ptr, int64_t &BytesOffset, |
--- |
366 |
const Value *Ptr, int64_t &BytesOffset, |
--- |
| 367 |
const DataLayout &DL, bool AllowNonInbounds = false) { |
--- |
367 |
const DataLayout &DL, bool AllowNonInbounds = false) { |
--- |
| 368 |
APInt OffsetAPInt(DL.getIndexTypeSizeInBits(Ptr->getType()), 0); |
0 |
368 |
APInt OffsetAPInt(DL.getIndexTypeSizeInBits(Ptr->getType()), 0); |
0 |
| 369 |
const Value *Base = |
--- |
369 |
const Value *Base = |
--- |
| 370 |
stripAndAccumulateOffsets(A, QueryingAA, Ptr, DL, OffsetAPInt, |
0 |
370 |
stripAndAccumulateOffsets(A, QueryingAA, Ptr, DL, OffsetAPInt, |
0 |
| 371 |
/* GetMinOffset */ true, AllowNonInbounds); |
--- |
371 |
/* GetMinOffset */ true, AllowNonInbounds); |
--- |
| 372 |
|
--- |
372 |
|
--- |
| 373 |
BytesOffset = OffsetAPInt.getSExtValue(); |
0 |
373 |
BytesOffset = OffsetAPInt.getSExtValue(); |
0 |
| 374 |
return Base; |
0 |
374 |
return Base; |
0 |
| 375 |
} |
0 |
375 |
} |
0 |
| 376 |
|
--- |
376 |
|
--- |
| 377 |
/// Clamp the information known for all returned values of a function |
--- |
377 |
/// Clamp the information known for all returned values of a function |
--- |
| 378 |
/// (identified by \p QueryingAA) into \p S. |
--- |
378 |
/// (identified by \p QueryingAA) into \p S. |
--- |
| 379 |
template
| --- |
379 |
template
| --- |
| |
| 380 |
Attribute::AttrKind IRAttributeKind = Attribute::None, |
--- |
380 |
Attribute::AttrKind IRAttributeKind = Attribute::None, |
--- |
| 381 |
bool RecurseForSelectAndPHI = true> |
--- |
381 |
bool RecurseForSelectAndPHI = true> |
--- |
| 382 |
static void clampReturnedValueStates( |
0 |
382 |
static void clampReturnedValueStates( |
0 |
| 383 |
Attributor &A, const AAType &QueryingAA, StateType &S, |
--- |
383 |
Attributor &A, const AAType &QueryingAA, StateType &S, |
--- |
| 384 |
const IRPosition::CallBaseContext *CBContext = nullptr) { |
--- |
384 |
const IRPosition::CallBaseContext *CBContext = nullptr) { |
--- |
| 385 |
LLVM_DEBUG(dbgs() << "[Attributor] Clamp return value states for " |
0 |
385 |
LLVM_DEBUG(dbgs() << "[Attributor] Clamp return value states for " |
0 |
| 386 |
<< QueryingAA << " into " << S << "\n"); |
--- |
386 |
<< QueryingAA << " into " << S << "\n"); |
--- |
| 387 |
|
--- |
387 |
|
--- |
| 388 |
assert((QueryingAA.getIRPosition().getPositionKind() == |
0 |
388 |
assert((QueryingAA.getIRPosition().getPositionKind() == |
0 |
| 389 |
IRPosition::IRP_RETURNED || |
--- |
389 |
IRPosition::IRP_RETURNED || |
--- |
| 390 |
QueryingAA.getIRPosition().getPositionKind() == |
--- |
390 |
QueryingAA.getIRPosition().getPositionKind() == |
--- |
| 391 |
IRPosition::IRP_CALL_SITE_RETURNED) && |
--- |
391 |
IRPosition::IRP_CALL_SITE_RETURNED) && |
--- |
| 392 |
"Can only clamp returned value states for a function returned or call " |
--- |
392 |
"Can only clamp returned value states for a function returned or call " |
--- |
| 393 |
"site returned position!"); |
--- |
393 |
"site returned position!"); |
--- |
| 394 |
|
--- |
394 |
|
--- |
| 395 |
// Use an optional state as there might not be any return values and we want |
--- |
395 |
// Use an optional state as there might not be any return values and we want |
--- |
| 396 |
// to join (IntegerState::operator&) the state of all there are. |
--- |
396 |
// to join (IntegerState::operator&) the state of all there are. |
--- |
| 397 |
std::optional T; |
0 |
397 |
std::optional T; |
0 |
| 398 |
|
--- |
398 |
|
--- |
| 399 |
// Callback for each possibly returned value. |
--- |
399 |
// Callback for each possibly returned value. |
--- |
| 400 |
auto CheckReturnValue = [&](Value &RV) -> bool { |
0 |
400 |
auto CheckReturnValue = [&](Value &RV) -> bool { |
0 |
| 401 |
const IRPosition &RVPos = IRPosition::value(RV, CBContext); |
0 |
401 |
const IRPosition &RVPos = IRPosition::value(RV, CBContext); |
0 |
| 402 |
// If possible, use the hasAssumedIRAttr interface. |
--- |
402 |
// If possible, use the hasAssumedIRAttr interface. |
--- |
| 403 |
if (IRAttributeKind != Attribute::None) { |
--- |
403 |
if (IRAttributeKind != Attribute::None) { |
--- |
| 404 |
bool IsKnown; |
--- |
404 |
bool IsKnown; |
--- |
| 405 |
return AA::hasAssumedIRAttr( |
0 |
405 |
return AA::hasAssumedIRAttr( |
0 |
| 406 |
A, &QueryingAA, RVPos, DepClassTy::REQUIRED, IsKnown); |
0 |
406 |
A, &QueryingAA, RVPos, DepClassTy::REQUIRED, IsKnown); |
0 |
| 407 |
} |
--- |
407 |
} |
--- |
| 408 |
|
--- |
408 |
|
--- |
| 409 |
const AAType *AA = |
--- |
409 |
const AAType *AA = |
--- |
| 410 |
A.getAAFor(QueryingAA, RVPos, DepClassTy::REQUIRED); |
0 |
410 |
A.getAAFor(QueryingAA, RVPos, DepClassTy::REQUIRED); |
0 |
| 411 |
if (!AA) |
0 |
411 |
if (!AA) |
0 |
| 412 |
return false; |
0 |
412 |
return false; |
0 |
| 413 |
LLVM_DEBUG(dbgs() << "[Attributor] RV: " << RV |
0 |
413 |
LLVM_DEBUG(dbgs() << "[Attributor] RV: " << RV |
0 |
| 414 |
<< " AA: " << AA->getAsStr(&A) << " @ " << RVPos << "\n"); |
--- |
414 |
<< " AA: " << AA->getAsStr(&A) << " @ " << RVPos << "\n"); |
--- |
| 415 |
const StateType &AAS = AA->getState(); |
0 |
415 |
const StateType &AAS = AA->getState(); |
0 |
| 416 |
if (!T) |
0 |
416 |
if (!T) |
0 |
| 417 |
T = StateType::getBestState(AAS); |
0 |
417 |
T = StateType::getBestState(AAS); |
0 |
| 418 |
*T &= AAS; |
0 |
418 |
*T &= AAS; |
0 |
| 419 |
LLVM_DEBUG(dbgs() << "[Attributor] AA State: " << AAS << " RV State: " << T |
0 |
419 |
LLVM_DEBUG(dbgs() << "[Attributor] AA State: " << AAS << " RV State: " << T |
0 |
| 420 |
<< "\n"); |
--- |
420 |
<< "\n"); |
--- |
| 421 |
return T->isValidState(); |
0 |
421 |
return T->isValidState(); |
0 |
| 422 |
}; |
--- |
422 |
}; |
--- |
| 423 |
|
--- |
423 |
|
--- |
| 424 |
if (!A.checkForAllReturnedValues(CheckReturnValue, QueryingAA, |
0 |
424 |
if (!A.checkForAllReturnedValues(CheckReturnValue, QueryingAA, |
0 |
| 425 |
AA::ValueScope::Intraprocedural, |
--- |
425 |
AA::ValueScope::Intraprocedural, |
--- |
| 426 |
RecurseForSelectAndPHI)) |
--- |
426 |
RecurseForSelectAndPHI)) |
--- |
| 427 |
S.indicatePessimisticFixpoint(); |
0 |
427 |
S.indicatePessimisticFixpoint(); |
0 |
| 428 |
else if (T) |
0 |
428 |
else if (T) |
0 |
| 429 |
S ^= *T; |
0 |
429 |
S ^= *T; |
0 |
| 430 |
} |
0 |
430 |
} |
0 |
| 431 |
|
--- |
431 |
|
--- |
| 432 |
namespace { |
--- |
432 |
namespace { |
--- |
| 433 |
/// Helper class for generic deduction: return value -> returned position. |
--- |
433 |
/// Helper class for generic deduction: return value -> returned position. |
--- |
| 434 |
template
| --- |
434 |
template
| --- |
| |
| 435 |
typename StateType = typename BaseType::StateType, |
--- |
435 |
typename StateType = typename BaseType::StateType, |
--- |
| 436 |
bool PropagateCallBaseContext = false, |
--- |
436 |
bool PropagateCallBaseContext = false, |
--- |
| 437 |
Attribute::AttrKind IRAttributeKind = Attribute::None, |
--- |
437 |
Attribute::AttrKind IRAttributeKind = Attribute::None, |
--- |
| 438 |
bool RecurseForSelectAndPHI = true> |
--- |
438 |
bool RecurseForSelectAndPHI = true> |
--- |
| 439 |
struct AAReturnedFromReturnedValues : public BaseType { |
--- |
439 |
struct AAReturnedFromReturnedValues : public BaseType { |
--- |
| 440 |
AAReturnedFromReturnedValues(const IRPosition &IRP, Attributor &A) |
0 |
440 |
AAReturnedFromReturnedValues(const IRPosition &IRP, Attributor &A) |
0 |
| 441 |
: BaseType(IRP, A) {} |
0 |
441 |
: BaseType(IRP, A) {} |
0 |
| 442 |
|
--- |
442 |
|
--- |
| 443 |
/// See AbstractAttribute::updateImpl(...). |
--- |
443 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 444 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
444 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 445 |
StateType S(StateType::getBestState(this->getState())); |
0 |
445 |
StateType S(StateType::getBestState(this->getState())); |
0 |
| 446 |
clampReturnedValueStates( |
0 |
446 |
clampReturnedValueStates( |
0 |
| 447 |
A, *this, S, |
--- |
447 |
A, *this, S, |
--- |
| 448 |
PropagateCallBaseContext ? this->getCallBaseContext() : nullptr); |
--- |
448 |
PropagateCallBaseContext ? this->getCallBaseContext() : nullptr); |
--- |
| 449 |
// TODO: If we know we visited all returned values, thus no are assumed |
--- |
449 |
// TODO: If we know we visited all returned values, thus no are assumed |
--- |
| 450 |
// dead, we can take the known information from the state T. |
--- |
450 |
// dead, we can take the known information from the state T. |
--- |
| 451 |
return clampStateAndIndicateChange(this->getState(), S); |
0 |
451 |
return clampStateAndIndicateChange(this->getState(), S); |
0 |
| 452 |
} |
0 |
452 |
} |
0 |
| 453 |
}; |
--- |
453 |
}; |
--- |
| 454 |
|
--- |
454 |
|
--- |
| 455 |
/// Clamp the information known at all call sites for a given argument |
--- |
455 |
/// Clamp the information known at all call sites for a given argument |
--- |
| 456 |
/// (identified by \p QueryingAA) into \p S. |
--- |
456 |
/// (identified by \p QueryingAA) into \p S. |
--- |
| 457 |
template
| --- |
457 |
template
| --- |
| |
| 458 |
Attribute::AttrKind IRAttributeKind = Attribute::None> |
--- |
458 |
Attribute::AttrKind IRAttributeKind = Attribute::None> |
--- |
| 459 |
static void clampCallSiteArgumentStates(Attributor &A, const AAType &QueryingAA, |
0 |
459 |
static void clampCallSiteArgumentStates(Attributor &A, const AAType &QueryingAA, |
0 |
| 460 |
StateType &S) { |
--- |
460 |
StateType &S) { |
--- |
| 461 |
LLVM_DEBUG(dbgs() << "[Attributor] Clamp call site argument states for " |
0 |
461 |
LLVM_DEBUG(dbgs() << "[Attributor] Clamp call site argument states for " |
0 |
| 462 |
<< QueryingAA << " into " << S << "\n"); |
--- |
462 |
<< QueryingAA << " into " << S << "\n"); |
--- |
| 463 |
|
--- |
463 |
|
--- |
| 464 |
assert(QueryingAA.getIRPosition().getPositionKind() == |
0 |
464 |
assert(QueryingAA.getIRPosition().getPositionKind() == |
0 |
| 465 |
IRPosition::IRP_ARGUMENT && |
--- |
465 |
IRPosition::IRP_ARGUMENT && |
--- |
| 466 |
"Can only clamp call site argument states for an argument position!"); |
--- |
466 |
"Can only clamp call site argument states for an argument position!"); |
--- |
| 467 |
|
--- |
467 |
|
--- |
| 468 |
// Use an optional state as there might not be any return values and we want |
--- |
468 |
// Use an optional state as there might not be any return values and we want |
--- |
| 469 |
// to join (IntegerState::operator&) the state of all there are. |
--- |
469 |
// to join (IntegerState::operator&) the state of all there are. |
--- |
| 470 |
std::optional T; |
0 |
470 |
std::optional T; |
0 |
| 471 |
|
--- |
471 |
|
--- |
| 472 |
// The argument number which is also the call site argument number. |
--- |
472 |
// The argument number which is also the call site argument number. |
--- |
| 473 |
unsigned ArgNo = QueryingAA.getIRPosition().getCallSiteArgNo(); |
0 |
473 |
unsigned ArgNo = QueryingAA.getIRPosition().getCallSiteArgNo(); |
0 |
| 474 |
|
--- |
474 |
|
--- |
| 475 |
auto CallSiteCheck = [&](AbstractCallSite ACS) { |
0 |
475 |
auto CallSiteCheck = [&](AbstractCallSite ACS) { |
0 |
| 476 |
const IRPosition &ACSArgPos = IRPosition::callsite_argument(ACS, ArgNo); |
0 |
476 |
const IRPosition &ACSArgPos = IRPosition::callsite_argument(ACS, ArgNo); |
0 |
| 477 |
// Check if a coresponding argument was found or if it is on not associated |
--- |
477 |
// Check if a coresponding argument was found or if it is on not associated |
--- |
| 478 |
// (which can happen for callback calls). |
--- |
478 |
// (which can happen for callback calls). |
--- |
| 479 |
if (ACSArgPos.getPositionKind() == IRPosition::IRP_INVALID) |
0 |
479 |
if (ACSArgPos.getPositionKind() == IRPosition::IRP_INVALID) |
0 |
| 480 |
return false; |
0 |
480 |
return false; |
0 |
| 481 |
|
--- |
481 |
|
--- |
| 482 |
// If possible, use the hasAssumedIRAttr interface. |
--- |
482 |
// If possible, use the hasAssumedIRAttr interface. |
--- |
| 483 |
if (IRAttributeKind != Attribute::None) { |
--- |
483 |
if (IRAttributeKind != Attribute::None) { |
--- |
| 484 |
bool IsKnown; |
--- |
484 |
bool IsKnown; |
--- |
| 485 |
return AA::hasAssumedIRAttr( |
0 |
485 |
return AA::hasAssumedIRAttr( |
0 |
| 486 |
A, &QueryingAA, ACSArgPos, DepClassTy::REQUIRED, IsKnown); |
0 |
486 |
A, &QueryingAA, ACSArgPos, DepClassTy::REQUIRED, IsKnown); |
0 |
| 487 |
} |
--- |
487 |
} |
--- |
| 488 |
|
--- |
488 |
|
--- |
| 489 |
const AAType *AA = |
--- |
489 |
const AAType *AA = |
--- |
| 490 |
A.getAAFor(QueryingAA, ACSArgPos, DepClassTy::REQUIRED); |
0 |
490 |
A.getAAFor(QueryingAA, ACSArgPos, DepClassTy::REQUIRED); |
0 |
| 491 |
if (!AA) |
0 |
491 |
if (!AA) |
0 |
| 492 |
return false; |
0 |
492 |
return false; |
0 |
| 493 |
LLVM_DEBUG(dbgs() << "[Attributor] ACS: " << *ACS.getInstruction() |
0 |
493 |
LLVM_DEBUG(dbgs() << "[Attributor] ACS: " << *ACS.getInstruction() |
0 |
| 494 |
<< " AA: " << AA->getAsStr(&A) << " @" << ACSArgPos |
--- |
494 |
<< " AA: " << AA->getAsStr(&A) << " @" << ACSArgPos |
--- |
| 495 |
<< "\n"); |
--- |
495 |
<< "\n"); |
--- |
| 496 |
const StateType &AAS = AA->getState(); |
0 |
496 |
const StateType &AAS = AA->getState(); |
0 |
| 497 |
if (!T) |
0 |
497 |
if (!T) |
0 |
| 498 |
T = StateType::getBestState(AAS); |
0 |
498 |
T = StateType::getBestState(AAS); |
0 |
| 499 |
*T &= AAS; |
0 |
499 |
*T &= AAS; |
0 |
| 500 |
LLVM_DEBUG(dbgs() << "[Attributor] AA State: " << AAS << " CSA State: " << T |
0 |
500 |
LLVM_DEBUG(dbgs() << "[Attributor] AA State: " << AAS << " CSA State: " << T |
0 |
| 501 |
<< "\n"); |
--- |
501 |
<< "\n"); |
--- |
| 502 |
return T->isValidState(); |
0 |
502 |
return T->isValidState(); |
0 |
| 503 |
}; |
--- |
503 |
}; |
--- |
| 504 |
|
--- |
504 |
|
--- |
| 505 |
bool UsedAssumedInformation = false; |
0 |
505 |
bool UsedAssumedInformation = false; |
0 |
| 506 |
if (!A.checkForAllCallSites(CallSiteCheck, QueryingAA, true, |
0 |
506 |
if (!A.checkForAllCallSites(CallSiteCheck, QueryingAA, true, |
0 |
| 507 |
UsedAssumedInformation)) |
--- |
507 |
UsedAssumedInformation)) |
--- |
| 508 |
S.indicatePessimisticFixpoint(); |
0 |
508 |
S.indicatePessimisticFixpoint(); |
0 |
| 509 |
else if (T) |
0 |
509 |
else if (T) |
0 |
| 510 |
S ^= *T; |
0 |
510 |
S ^= *T; |
0 |
| 511 |
} |
0 |
511 |
} |
0 |
| 512 |
|
--- |
512 |
|
--- |
| 513 |
/// This function is the bridge between argument position and the call base |
--- |
513 |
/// This function is the bridge between argument position and the call base |
--- |
| 514 |
/// context. |
--- |
514 |
/// context. |
--- |
| 515 |
template
| --- |
515 |
template
| --- |
| |
| 516 |
typename StateType = typename AAType::StateType, |
--- |
516 |
typename StateType = typename AAType::StateType, |
--- |
| 517 |
Attribute::AttrKind IRAttributeKind = Attribute::None> |
--- |
517 |
Attribute::AttrKind IRAttributeKind = Attribute::None> |
--- |
| 518 |
bool getArgumentStateFromCallBaseContext(Attributor &A, |
0 |
518 |
bool getArgumentStateFromCallBaseContext(Attributor &A, |
0 |
| 519 |
BaseType &QueryingAttribute, |
--- |
519 |
BaseType &QueryingAttribute, |
--- |
| 520 |
IRPosition &Pos, StateType &State) { |
--- |
520 |
IRPosition &Pos, StateType &State) { |
--- |
| 521 |
assert((Pos.getPositionKind() == IRPosition::IRP_ARGUMENT) && |
0 |
521 |
assert((Pos.getPositionKind() == IRPosition::IRP_ARGUMENT) && |
0 |
| 522 |
"Expected an 'argument' position !"); |
--- |
522 |
"Expected an 'argument' position !"); |
--- |
| 523 |
const CallBase *CBContext = Pos.getCallBaseContext(); |
0 |
523 |
const CallBase *CBContext = Pos.getCallBaseContext(); |
0 |
| 524 |
if (!CBContext) |
0 |
524 |
if (!CBContext) |
0 |
| 525 |
return false; |
0 |
525 |
return false; |
0 |
| 526 |
|
--- |
526 |
|
--- |
| 527 |
int ArgNo = Pos.getCallSiteArgNo(); |
0 |
527 |
int ArgNo = Pos.getCallSiteArgNo(); |
0 |
| 528 |
assert(ArgNo >= 0 && "Invalid Arg No!"); |
0 |
528 |
assert(ArgNo >= 0 && "Invalid Arg No!"); |
0 |
| 529 |
const IRPosition CBArgPos = IRPosition::callsite_argument(*CBContext, ArgNo); |
0 |
529 |
const IRPosition CBArgPos = IRPosition::callsite_argument(*CBContext, ArgNo); |
0 |
| 530 |
|
--- |
530 |
|
--- |
| 531 |
// If possible, use the hasAssumedIRAttr interface. |
--- |
531 |
// If possible, use the hasAssumedIRAttr interface. |
--- |
| 532 |
if (IRAttributeKind != Attribute::None) { |
--- |
532 |
if (IRAttributeKind != Attribute::None) { |
--- |
| 533 |
bool IsKnown; |
--- |
533 |
bool IsKnown; |
--- |
| 534 |
return AA::hasAssumedIRAttr( |
0 |
534 |
return AA::hasAssumedIRAttr( |
0 |
| 535 |
A, &QueryingAttribute, CBArgPos, DepClassTy::REQUIRED, IsKnown); |
0 |
535 |
A, &QueryingAttribute, CBArgPos, DepClassTy::REQUIRED, IsKnown); |
0 |
| 536 |
} |
--- |
536 |
} |
--- |
| 537 |
|
--- |
537 |
|
--- |
| 538 |
const auto *AA = |
--- |
538 |
const auto *AA = |
--- |
| 539 |
A.getAAFor(QueryingAttribute, CBArgPos, DepClassTy::REQUIRED); |
0 |
539 |
A.getAAFor(QueryingAttribute, CBArgPos, DepClassTy::REQUIRED); |
0 |
| 540 |
if (!AA) |
0 |
540 |
if (!AA) |
0 |
| 541 |
return false; |
0 |
541 |
return false; |
0 |
| 542 |
const StateType &CBArgumentState = |
--- |
542 |
const StateType &CBArgumentState = |
--- |
| 543 |
static_cast(AA->getState()); |
0 |
543 |
static_cast(AA->getState()); |
0 |
| 544 |
|
--- |
544 |
|
--- |
| 545 |
LLVM_DEBUG(dbgs() << "[Attributor] Briding Call site context to argument" |
0 |
545 |
LLVM_DEBUG(dbgs() << "[Attributor] Briding Call site context to argument" |
0 |
| 546 |
<< "Position:" << Pos << "CB Arg state:" << CBArgumentState |
--- |
546 |
<< "Position:" << Pos << "CB Arg state:" << CBArgumentState |
--- |
| 547 |
<< "\n"); |
--- |
547 |
<< "\n"); |
--- |
| 548 |
|
--- |
548 |
|
--- |
| 549 |
// NOTE: If we want to do call site grouping it should happen here. |
--- |
549 |
// NOTE: If we want to do call site grouping it should happen here. |
--- |
| 550 |
State ^= CBArgumentState; |
0 |
550 |
State ^= CBArgumentState; |
0 |
| 551 |
return true; |
0 |
551 |
return true; |
0 |
| 552 |
} |
--- |
552 |
} |
--- |
| 553 |
|
--- |
553 |
|
--- |
| 554 |
/// Helper class for generic deduction: call site argument -> argument position. |
--- |
554 |
/// Helper class for generic deduction: call site argument -> argument position. |
--- |
| 555 |
template
| --- |
555 |
template
| --- |
| |
| 556 |
typename StateType = typename AAType::StateType, |
--- |
556 |
typename StateType = typename AAType::StateType, |
--- |
| 557 |
bool BridgeCallBaseContext = false, |
--- |
557 |
bool BridgeCallBaseContext = false, |
--- |
| 558 |
Attribute::AttrKind IRAttributeKind = Attribute::None> |
--- |
558 |
Attribute::AttrKind IRAttributeKind = Attribute::None> |
--- |
| 559 |
struct AAArgumentFromCallSiteArguments : public BaseType { |
--- |
559 |
struct AAArgumentFromCallSiteArguments : public BaseType { |
--- |
| 560 |
AAArgumentFromCallSiteArguments(const IRPosition &IRP, Attributor &A) |
0 |
560 |
AAArgumentFromCallSiteArguments(const IRPosition &IRP, Attributor &A) |
0 |
| 561 |
: BaseType(IRP, A) {} |
0 |
561 |
: BaseType(IRP, A) {} |
0 |
| 562 |
|
--- |
562 |
|
--- |
| 563 |
/// See AbstractAttribute::updateImpl(...). |
--- |
563 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 564 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
564 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 565 |
StateType S = StateType::getBestState(this->getState()); |
0 |
565 |
StateType S = StateType::getBestState(this->getState()); |
0 |
| 566 |
|
--- |
566 |
|
--- |
| 567 |
if (BridgeCallBaseContext) { |
--- |
567 |
if (BridgeCallBaseContext) { |
--- |
| 568 |
bool Success = |
--- |
568 |
bool Success = |
--- |
| 569 |
getArgumentStateFromCallBaseContext
| --- |
569 |
getArgumentStateFromCallBaseContext
| --- |
| |
| 570 |
IRAttributeKind>( |
0 |
570 |
IRAttributeKind>( |
0 |
| 571 |
A, *this, this->getIRPosition(), S); |
--- |
571 |
A, *this, this->getIRPosition(), S); |
--- |
| 572 |
if (Success) |
0 |
572 |
if (Success) |
0 |
| 573 |
return clampStateAndIndicateChange(this->getState(), S); |
0 |
573 |
return clampStateAndIndicateChange(this->getState(), S); |
0 |
| 574 |
} |
--- |
574 |
} |
--- |
| 575 |
clampCallSiteArgumentStates(A, *this, |
0 |
575 |
clampCallSiteArgumentStates(A, *this, |
0 |
| 576 |
S); |
--- |
576 |
S); |
--- |
| 577 |
|
--- |
577 |
|
--- |
| 578 |
// TODO: If we know we visited all incoming values, thus no are assumed |
--- |
578 |
// TODO: If we know we visited all incoming values, thus no are assumed |
--- |
| 579 |
// dead, we can take the known information from the state T. |
--- |
579 |
// dead, we can take the known information from the state T. |
--- |
| 580 |
return clampStateAndIndicateChange(this->getState(), S); |
0 |
580 |
return clampStateAndIndicateChange(this->getState(), S); |
0 |
| 581 |
} |
0 |
581 |
} |
0 |
| 582 |
}; |
--- |
582 |
}; |
--- |
| 583 |
|
--- |
583 |
|
--- |
| 584 |
/// Helper class for generic replication: function returned -> cs returned. |
--- |
584 |
/// Helper class for generic replication: function returned -> cs returned. |
--- |
| 585 |
template
| --- |
585 |
template
| --- |
| |
| 586 |
typename StateType = typename BaseType::StateType, |
--- |
586 |
typename StateType = typename BaseType::StateType, |
--- |
| 587 |
bool IntroduceCallBaseContext = false, |
--- |
587 |
bool IntroduceCallBaseContext = false, |
--- |
| 588 |
Attribute::AttrKind IRAttributeKind = Attribute::None> |
--- |
588 |
Attribute::AttrKind IRAttributeKind = Attribute::None> |
--- |
| 589 |
struct AACallSiteReturnedFromReturned : public BaseType { |
--- |
589 |
struct AACallSiteReturnedFromReturned : public BaseType { |
--- |
| 590 |
AACallSiteReturnedFromReturned(const IRPosition &IRP, Attributor &A) |
0 |
590 |
AACallSiteReturnedFromReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 591 |
: BaseType(IRP, A) {} |
0 |
591 |
: BaseType(IRP, A) {} |
0 |
| 592 |
|
--- |
592 |
|
--- |
| 593 |
/// See AbstractAttribute::updateImpl(...). |
--- |
593 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 594 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
594 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 595 |
assert(this->getIRPosition().getPositionKind() == |
0 |
595 |
assert(this->getIRPosition().getPositionKind() == |
0 |
| 596 |
IRPosition::IRP_CALL_SITE_RETURNED && |
--- |
596 |
IRPosition::IRP_CALL_SITE_RETURNED && |
--- |
| 597 |
"Can only wrap function returned positions for call site returned " |
--- |
597 |
"Can only wrap function returned positions for call site returned " |
--- |
| 598 |
"positions!"); |
--- |
598 |
"positions!"); |
--- |
| 599 |
auto &S = this->getState(); |
0 |
599 |
auto &S = this->getState(); |
0 |
| 600 |
|
--- |
600 |
|
--- |
| 601 |
const Function *AssociatedFunction = |
--- |
601 |
const Function *AssociatedFunction = |
--- |
| 602 |
this->getIRPosition().getAssociatedFunction(); |
0 |
602 |
this->getIRPosition().getAssociatedFunction(); |
0 |
| 603 |
if (!AssociatedFunction) |
0 |
603 |
if (!AssociatedFunction) |
0 |
| 604 |
return S.indicatePessimisticFixpoint(); |
0 |
604 |
return S.indicatePessimisticFixpoint(); |
0 |
| 605 |
|
--- |
605 |
|
--- |
| 606 |
CallBase &CBContext = cast(this->getAnchorValue()); |
0 |
606 |
CallBase &CBContext = cast(this->getAnchorValue()); |
0 |
| 607 |
if (IntroduceCallBaseContext) |
--- |
607 |
if (IntroduceCallBaseContext) |
--- |
| 608 |
LLVM_DEBUG(dbgs() << "[Attributor] Introducing call base context:" |
0 |
608 |
LLVM_DEBUG(dbgs() << "[Attributor] Introducing call base context:" |
0 |
| 609 |
<< CBContext << "\n"); |
--- |
609 |
<< CBContext << "\n"); |
--- |
| 610 |
|
--- |
610 |
|
--- |
| 611 |
IRPosition FnPos = IRPosition::returned( |
0 |
611 |
IRPosition FnPos = IRPosition::returned( |
0 |
| 612 |
*AssociatedFunction, IntroduceCallBaseContext ? &CBContext : nullptr); |
--- |
612 |
*AssociatedFunction, IntroduceCallBaseContext ? &CBContext : nullptr); |
--- |
| 613 |
|
--- |
613 |
|
--- |
| 614 |
// If possible, use the hasAssumedIRAttr interface. |
--- |
614 |
// If possible, use the hasAssumedIRAttr interface. |
--- |
| 615 |
if (IRAttributeKind != Attribute::None) { |
--- |
615 |
if (IRAttributeKind != Attribute::None) { |
--- |
| 616 |
bool IsKnown; |
--- |
616 |
bool IsKnown; |
--- |
| 617 |
if (!AA::hasAssumedIRAttr(A, this, FnPos, |
0 |
617 |
if (!AA::hasAssumedIRAttr(A, this, FnPos, |
0 |
| 618 |
DepClassTy::REQUIRED, IsKnown)) |
--- |
618 |
DepClassTy::REQUIRED, IsKnown)) |
--- |
| 619 |
return S.indicatePessimisticFixpoint(); |
0 |
619 |
return S.indicatePessimisticFixpoint(); |
0 |
| 620 |
return ChangeStatus::UNCHANGED; |
0 |
620 |
return ChangeStatus::UNCHANGED; |
0 |
| 621 |
} |
--- |
621 |
} |
--- |
| 622 |
|
--- |
622 |
|
--- |
| 623 |
const AAType *AA = A.getAAFor(*this, FnPos, DepClassTy::REQUIRED); |
0 |
623 |
const AAType *AA = A.getAAFor(*this, FnPos, DepClassTy::REQUIRED); |
0 |
| 624 |
if (!AA) |
0 |
624 |
if (!AA) |
0 |
| 625 |
return S.indicatePessimisticFixpoint(); |
0 |
625 |
return S.indicatePessimisticFixpoint(); |
0 |
| 626 |
return clampStateAndIndicateChange(S, AA->getState()); |
0 |
626 |
return clampStateAndIndicateChange(S, AA->getState()); |
0 |
| 627 |
} |
--- |
627 |
} |
--- |
| 628 |
}; |
--- |
628 |
}; |
--- |
| 629 |
|
--- |
629 |
|
--- |
| 630 |
/// Helper function to accumulate uses. |
--- |
630 |
/// Helper function to accumulate uses. |
--- |
| 631 |
template |
--- |
631 |
template |
--- |
| 632 |
static void followUsesInContext(AAType &AA, Attributor &A, |
0 |
632 |
static void followUsesInContext(AAType &AA, Attributor &A, |
0 |
| 633 |
MustBeExecutedContextExplorer &Explorer, |
--- |
633 |
MustBeExecutedContextExplorer &Explorer, |
--- |
| 634 |
const Instruction *CtxI, |
--- |
634 |
const Instruction *CtxI, |
--- |
| 635 |
SetVector &Uses, |
--- |
635 |
SetVector &Uses, |
--- |
| 636 |
StateType &State) { |
--- |
636 |
StateType &State) { |
--- |
| 637 |
auto EIt = Explorer.begin(CtxI), EEnd = Explorer.end(CtxI); |
0 |
637 |
auto EIt = Explorer.begin(CtxI), EEnd = Explorer.end(CtxI); |
0 |
| 638 |
for (unsigned u = 0; u < Uses.size(); ++u) { |
0 |
638 |
for (unsigned u = 0; u < Uses.size(); ++u) { |
0 |
| 639 |
const Use *U = Uses[u]; |
0 |
639 |
const Use *U = Uses[u]; |
0 |
| 640 |
if (const Instruction *UserI = dyn_cast(U->getUser())) { |
0 |
640 |
if (const Instruction *UserI = dyn_cast(U->getUser())) { |
0 |
| 641 |
bool Found = Explorer.findInContextOf(UserI, EIt, EEnd); |
0 |
641 |
bool Found = Explorer.findInContextOf(UserI, EIt, EEnd); |
0 |
| 642 |
if (Found && AA.followUseInMBEC(A, U, UserI, State)) |
0 |
642 |
if (Found && AA.followUseInMBEC(A, U, UserI, State)) |
0 |
| 643 |
for (const Use &Us : UserI->uses()) |
0 |
643 |
for (const Use &Us : UserI->uses()) |
0 |
| 644 |
Uses.insert(&Us); |
0 |
644 |
Uses.insert(&Us); |
0 |
| 645 |
} |
--- |
645 |
} |
--- |
| 646 |
} |
--- |
646 |
} |
--- |
| 647 |
} |
0 |
647 |
} |
0 |
| 648 |
|
--- |
648 |
|
--- |
| 649 |
/// Use the must-be-executed-context around \p I to add information into \p S. |
--- |
649 |
/// Use the must-be-executed-context around \p I to add information into \p S. |
--- |
| 650 |
/// The AAType class is required to have `followUseInMBEC` method with the |
--- |
650 |
/// The AAType class is required to have `followUseInMBEC` method with the |
--- |
| 651 |
/// following signature and behaviour: |
--- |
651 |
/// following signature and behaviour: |
--- |
| 652 |
/// |
--- |
652 |
/// |
--- |
| 653 |
/// bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I) |
--- |
653 |
/// bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I) |
--- |
| 654 |
/// U - Underlying use. |
--- |
654 |
/// U - Underlying use. |
--- |
| 655 |
/// I - The user of the \p U. |
--- |
655 |
/// I - The user of the \p U. |
--- |
| 656 |
/// Returns true if the value should be tracked transitively. |
--- |
656 |
/// Returns true if the value should be tracked transitively. |
--- |
| 657 |
/// |
--- |
657 |
/// |
--- |
| 658 |
template |
--- |
658 |
template |
--- |
| 659 |
static void followUsesInMBEC(AAType &AA, Attributor &A, StateType &S, |
0 |
659 |
static void followUsesInMBEC(AAType &AA, Attributor &A, StateType &S, |
0 |
| 660 |
Instruction &CtxI) { |
--- |
660 |
Instruction &CtxI) { |
--- |
| 661 |
MustBeExecutedContextExplorer *Explorer = |
--- |
661 |
MustBeExecutedContextExplorer *Explorer = |
--- |
| 662 |
A.getInfoCache().getMustBeExecutedContextExplorer(); |
0 |
662 |
A.getInfoCache().getMustBeExecutedContextExplorer(); |
0 |
| 663 |
if (!Explorer) |
0 |
663 |
if (!Explorer) |
0 |
| 664 |
return; |
0 |
664 |
return; |
0 |
| 665 |
|
--- |
665 |
|
--- |
| 666 |
// Container for (transitive) uses of the associated value. |
--- |
666 |
// Container for (transitive) uses of the associated value. |
--- |
| 667 |
SetVector Uses; |
0 |
667 |
SetVector Uses; |
0 |
| 668 |
for (const Use &U : AA.getIRPosition().getAssociatedValue().uses()) |
0 |
668 |
for (const Use &U : AA.getIRPosition().getAssociatedValue().uses()) |
0 |
| 669 |
Uses.insert(&U); |
0 |
669 |
Uses.insert(&U); |
0 |
| 670 |
|
--- |
670 |
|
--- |
| 671 |
followUsesInContext(AA, A, *Explorer, &CtxI, Uses, S); |
0 |
671 |
followUsesInContext(AA, A, *Explorer, &CtxI, Uses, S); |
0 |
| 672 |
|
--- |
672 |
|
--- |
| 673 |
if (S.isAtFixpoint()) |
0 |
673 |
if (S.isAtFixpoint()) |
0 |
| 674 |
return; |
0 |
674 |
return; |
0 |
| 675 |
|
--- |
675 |
|
--- |
| 676 |
SmallVector BrInsts; |
0 |
676 |
SmallVector BrInsts; |
0 |
| 677 |
auto Pred = [&](const Instruction *I) { |
0 |
677 |
auto Pred = [&](const Instruction *I) { |
0 |
| 678 |
if (const BranchInst *Br = dyn_cast(I)) |
0 |
678 |
if (const BranchInst *Br = dyn_cast(I)) |
0 |
| 679 |
if (Br->isConditional()) |
0 |
679 |
if (Br->isConditional()) |
0 |
| 680 |
BrInsts.push_back(Br); |
0 |
680 |
BrInsts.push_back(Br); |
0 |
| 681 |
return true; |
0 |
681 |
return true; |
0 |
| 682 |
}; |
--- |
682 |
}; |
--- |
| 683 |
|
--- |
683 |
|
--- |
| 684 |
// Here, accumulate conditional branch instructions in the context. We |
--- |
684 |
// Here, accumulate conditional branch instructions in the context. We |
--- |
| 685 |
// explore the child paths and collect the known states. The disjunction of |
--- |
685 |
// explore the child paths and collect the known states. The disjunction of |
--- |
| 686 |
// those states can be merged to its own state. Let ParentState_i be a state |
--- |
686 |
// those states can be merged to its own state. Let ParentState_i be a state |
--- |
| 687 |
// to indicate the known information for an i-th branch instruction in the |
--- |
687 |
// to indicate the known information for an i-th branch instruction in the |
--- |
| 688 |
// context. ChildStates are created for its successors respectively. |
--- |
688 |
// context. ChildStates are created for its successors respectively. |
--- |
| 689 |
// |
--- |
689 |
// |
--- |
| 690 |
// ParentS_1 = ChildS_{1, 1} /\ ChildS_{1, 2} /\ ... /\ ChildS_{1, n_1} |
--- |
690 |
// ParentS_1 = ChildS_{1, 1} /\ ChildS_{1, 2} /\ ... /\ ChildS_{1, n_1} |
--- |
| 691 |
// ParentS_2 = ChildS_{2, 1} /\ ChildS_{2, 2} /\ ... /\ ChildS_{2, n_2} |
--- |
691 |
// ParentS_2 = ChildS_{2, 1} /\ ChildS_{2, 2} /\ ... /\ ChildS_{2, n_2} |
--- |
| 692 |
// ... |
--- |
692 |
// ... |
--- |
| 693 |
// ParentS_m = ChildS_{m, 1} /\ ChildS_{m, 2} /\ ... /\ ChildS_{m, n_m} |
--- |
693 |
// ParentS_m = ChildS_{m, 1} /\ ChildS_{m, 2} /\ ... /\ ChildS_{m, n_m} |
--- |
| 694 |
// |
--- |
694 |
// |
--- |
| 695 |
// Known State |= ParentS_1 \/ ParentS_2 \/... \/ ParentS_m |
--- |
695 |
// Known State |= ParentS_1 \/ ParentS_2 \/... \/ ParentS_m |
--- |
| 696 |
// |
--- |
696 |
// |
--- |
| 697 |
// FIXME: Currently, recursive branches are not handled. For example, we |
--- |
697 |
// FIXME: Currently, recursive branches are not handled. For example, we |
--- |
| 698 |
// can't deduce that ptr must be dereferenced in below function. |
--- |
698 |
// can't deduce that ptr must be dereferenced in below function. |
--- |
| 699 |
// |
--- |
699 |
// |
--- |
| 700 |
// void f(int a, int c, int *ptr) { |
--- |
700 |
// void f(int a, int c, int *ptr) { |
--- |
| 701 |
// if(a) |
--- |
701 |
// if(a) |
--- |
| 702 |
// if (b) { |
--- |
702 |
// if (b) { |
--- |
| 703 |
// *ptr = 0; |
--- |
703 |
// *ptr = 0; |
--- |
| 704 |
// } else { |
--- |
704 |
// } else { |
--- |
| 705 |
// *ptr = 1; |
--- |
705 |
// *ptr = 1; |
--- |
| 706 |
// } |
--- |
706 |
// } |
--- |
| 707 |
// else { |
--- |
707 |
// else { |
--- |
| 708 |
// if (b) { |
--- |
708 |
// if (b) { |
--- |
| 709 |
// *ptr = 0; |
--- |
709 |
// *ptr = 0; |
--- |
| 710 |
// } else { |
--- |
710 |
// } else { |
--- |
| 711 |
// *ptr = 1; |
--- |
711 |
// *ptr = 1; |
--- |
| 712 |
// } |
--- |
712 |
// } |
--- |
| 713 |
// } |
--- |
713 |
// } |
--- |
| 714 |
// } |
--- |
714 |
// } |
--- |
| 715 |
|
--- |
715 |
|
--- |
| 716 |
Explorer->checkForAllContext(&CtxI, Pred); |
0 |
716 |
Explorer->checkForAllContext(&CtxI, Pred); |
0 |
| 717 |
for (const BranchInst *Br : BrInsts) { |
0 |
717 |
for (const BranchInst *Br : BrInsts) { |
0 |
| 718 |
StateType ParentState; |
0 |
718 |
StateType ParentState; |
0 |
| 719 |
|
--- |
719 |
|
--- |
| 720 |
// The known state of the parent state is a conjunction of children's |
--- |
720 |
// The known state of the parent state is a conjunction of children's |
--- |
| 721 |
// known states so it is initialized with a best state. |
--- |
721 |
// known states so it is initialized with a best state. |
--- |
| 722 |
ParentState.indicateOptimisticFixpoint(); |
0 |
722 |
ParentState.indicateOptimisticFixpoint(); |
0 |
| 723 |
|
--- |
723 |
|
--- |
| 724 |
for (const BasicBlock *BB : Br->successors()) { |
0 |
724 |
for (const BasicBlock *BB : Br->successors()) { |
0 |
| 725 |
StateType ChildState; |
0 |
725 |
StateType ChildState; |
0 |
| 726 |
|
--- |
726 |
|
--- |
| 727 |
size_t BeforeSize = Uses.size(); |
0 |
727 |
size_t BeforeSize = Uses.size(); |
0 |
| 728 |
followUsesInContext(AA, A, *Explorer, &BB->front(), Uses, ChildState); |
0 |
728 |
followUsesInContext(AA, A, *Explorer, &BB->front(), Uses, ChildState); |
0 |
| 729 |
|
--- |
729 |
|
--- |
| 730 |
// Erase uses which only appear in the child. |
--- |
730 |
// Erase uses which only appear in the child. |
--- |
| 731 |
for (auto It = Uses.begin() + BeforeSize; It != Uses.end();) |
0 |
731 |
for (auto It = Uses.begin() + BeforeSize; It != Uses.end();) |
0 |
| 732 |
It = Uses.erase(It); |
0 |
732 |
It = Uses.erase(It); |
0 |
| 733 |
|
--- |
733 |
|
--- |
| 734 |
ParentState &= ChildState; |
0 |
734 |
ParentState &= ChildState; |
0 |
| 735 |
} |
--- |
735 |
} |
--- |
| 736 |
|
--- |
736 |
|
--- |
| 737 |
// Use only known state. |
--- |
737 |
// Use only known state. |
--- |
| 738 |
S += ParentState; |
0 |
738 |
S += ParentState; |
0 |
| 739 |
} |
--- |
739 |
} |
--- |
| 740 |
} |
0 |
740 |
} |
0 |
| 741 |
} // namespace |
--- |
741 |
} // namespace |
--- |
| 742 |
|
--- |
742 |
|
--- |
| 743 |
/// ------------------------ PointerInfo --------------------------------------- |
--- |
743 |
/// ------------------------ PointerInfo --------------------------------------- |
--- |
| 744 |
|
--- |
744 |
|
--- |
| 745 |
namespace llvm { |
--- |
745 |
namespace llvm { |
--- |
| 746 |
namespace AA { |
--- |
746 |
namespace AA { |
--- |
| 747 |
namespace PointerInfo { |
--- |
747 |
namespace PointerInfo { |
--- |
| 748 |
|
--- |
748 |
|
--- |
| 749 |
struct State; |
--- |
749 |
struct State; |
--- |
| 750 |
|
--- |
750 |
|
--- |
| 751 |
} // namespace PointerInfo |
--- |
751 |
} // namespace PointerInfo |
--- |
| 752 |
} // namespace AA |
--- |
752 |
} // namespace AA |
--- |
| 753 |
|
--- |
753 |
|
--- |
| 754 |
/// Helper for AA::PointerInfo::Access DenseMap/Set usage. |
--- |
754 |
/// Helper for AA::PointerInfo::Access DenseMap/Set usage. |
--- |
| 755 |
template <> |
--- |
755 |
template <> |
--- |
| 756 |
struct DenseMapInfo : DenseMapInfo { |
--- |
756 |
struct DenseMapInfo : DenseMapInfo { |
--- |
| 757 |
using Access = AAPointerInfo::Access; |
--- |
757 |
using Access = AAPointerInfo::Access; |
--- |
| 758 |
static inline Access getEmptyKey(); |
--- |
758 |
static inline Access getEmptyKey(); |
--- |
| 759 |
static inline Access getTombstoneKey(); |
--- |
759 |
static inline Access getTombstoneKey(); |
--- |
| 760 |
static unsigned getHashValue(const Access &A); |
--- |
760 |
static unsigned getHashValue(const Access &A); |
--- |
| 761 |
static bool isEqual(const Access &LHS, const Access &RHS); |
--- |
761 |
static bool isEqual(const Access &LHS, const Access &RHS); |
--- |
| 762 |
}; |
--- |
762 |
}; |
--- |
| 763 |
|
--- |
763 |
|
--- |
| 764 |
/// Helper that allows RangeTy as a key in a DenseMap. |
--- |
764 |
/// Helper that allows RangeTy as a key in a DenseMap. |
--- |
| 765 |
template <> struct DenseMapInfo { |
--- |
765 |
template <> struct DenseMapInfo { |
--- |
| 766 |
static inline AA::RangeTy getEmptyKey() { |
0 |
766 |
static inline AA::RangeTy getEmptyKey() { |
0 |
| 767 |
auto EmptyKey = DenseMapInfo::getEmptyKey(); |
0 |
767 |
auto EmptyKey = DenseMapInfo::getEmptyKey(); |
0 |
| 768 |
return AA::RangeTy{EmptyKey, EmptyKey}; |
0 |
768 |
return AA::RangeTy{EmptyKey, EmptyKey}; |
0 |
| 769 |
} |
--- |
769 |
} |
--- |
| 770 |
|
--- |
770 |
|
--- |
| 771 |
static inline AA::RangeTy getTombstoneKey() { |
0 |
771 |
static inline AA::RangeTy getTombstoneKey() { |
0 |
| 772 |
auto TombstoneKey = DenseMapInfo::getTombstoneKey(); |
0 |
772 |
auto TombstoneKey = DenseMapInfo::getTombstoneKey(); |
0 |
| 773 |
return AA::RangeTy{TombstoneKey, TombstoneKey}; |
0 |
773 |
return AA::RangeTy{TombstoneKey, TombstoneKey}; |
0 |
| 774 |
} |
--- |
774 |
} |
--- |
| 775 |
|
--- |
775 |
|
--- |
| 776 |
static unsigned getHashValue(const AA::RangeTy &Range) { |
0 |
776 |
static unsigned getHashValue(const AA::RangeTy &Range) { |
0 |
| 777 |
return detail::combineHashValue( |
0 |
777 |
return detail::combineHashValue( |
0 |
| 778 |
DenseMapInfo::getHashValue(Range.Offset), |
0 |
778 |
DenseMapInfo::getHashValue(Range.Offset), |
0 |
| 779 |
DenseMapInfo::getHashValue(Range.Size)); |
0 |
779 |
DenseMapInfo::getHashValue(Range.Size)); |
0 |
| 780 |
} |
--- |
780 |
} |
--- |
| 781 |
|
--- |
781 |
|
--- |
| 782 |
static bool isEqual(const AA::RangeTy &A, const AA::RangeTy B) { |
0 |
782 |
static bool isEqual(const AA::RangeTy &A, const AA::RangeTy B) { |
0 |
| 783 |
return A == B; |
0 |
783 |
return A == B; |
0 |
| 784 |
} |
--- |
784 |
} |
--- |
| 785 |
}; |
--- |
785 |
}; |
--- |
| 786 |
|
--- |
786 |
|
--- |
| 787 |
/// Helper for AA::PointerInfo::Access DenseMap/Set usage ignoring everythign |
--- |
787 |
/// Helper for AA::PointerInfo::Access DenseMap/Set usage ignoring everythign |
--- |
| 788 |
/// but the instruction |
--- |
788 |
/// but the instruction |
--- |
| 789 |
struct AccessAsInstructionInfo : DenseMapInfo { |
--- |
789 |
struct AccessAsInstructionInfo : DenseMapInfo { |
--- |
| 790 |
using Base = DenseMapInfo; |
--- |
790 |
using Base = DenseMapInfo; |
--- |
| 791 |
using Access = AAPointerInfo::Access; |
--- |
791 |
using Access = AAPointerInfo::Access; |
--- |
| 792 |
static inline Access getEmptyKey(); |
--- |
792 |
static inline Access getEmptyKey(); |
--- |
| 793 |
static inline Access getTombstoneKey(); |
--- |
793 |
static inline Access getTombstoneKey(); |
--- |
| 794 |
static unsigned getHashValue(const Access &A); |
--- |
794 |
static unsigned getHashValue(const Access &A); |
--- |
| 795 |
static bool isEqual(const Access &LHS, const Access &RHS); |
--- |
795 |
static bool isEqual(const Access &LHS, const Access &RHS); |
--- |
| 796 |
}; |
--- |
796 |
}; |
--- |
| 797 |
|
--- |
797 |
|
--- |
| 798 |
} // namespace llvm |
--- |
798 |
} // namespace llvm |
--- |
| 799 |
|
--- |
799 |
|
--- |
| 800 |
/// A type to track pointer/struct usage and accesses for AAPointerInfo. |
--- |
800 |
/// A type to track pointer/struct usage and accesses for AAPointerInfo. |
--- |
| 801 |
struct AA::PointerInfo::State : public AbstractState { |
--- |
801 |
struct AA::PointerInfo::State : public AbstractState { |
--- |
| 802 |
/// Return the best possible representable state. |
--- |
802 |
/// Return the best possible representable state. |
--- |
| 803 |
static State getBestState(const State &SIS) { return State(); } |
--- |
803 |
static State getBestState(const State &SIS) { return State(); } |
--- |
| 804 |
|
--- |
804 |
|
--- |
| 805 |
/// Return the worst possible representable state. |
--- |
805 |
/// Return the worst possible representable state. |
--- |
| 806 |
static State getWorstState(const State &SIS) { |
--- |
806 |
static State getWorstState(const State &SIS) { |
--- |
| 807 |
State R; |
--- |
807 |
State R; |
--- |
| 808 |
R.indicatePessimisticFixpoint(); |
--- |
808 |
R.indicatePessimisticFixpoint(); |
--- |
| 809 |
return R; |
--- |
809 |
return R; |
--- |
| 810 |
} |
--- |
810 |
} |
--- |
| 811 |
|
--- |
811 |
|
--- |
| 812 |
State() = default; |
0 |
812 |
State() = default; |
0 |
| 813 |
State(State &&SIS) = default; |
--- |
813 |
State(State &&SIS) = default; |
--- |
| 814 |
|
--- |
814 |
|
--- |
| 815 |
const State &getAssumed() const { return *this; } |
--- |
815 |
const State &getAssumed() const { return *this; } |
--- |
| 816 |
|
--- |
816 |
|
--- |
| 817 |
/// See AbstractState::isValidState(). |
--- |
817 |
/// See AbstractState::isValidState(). |
--- |
| 818 |
bool isValidState() const override { return BS.isValidState(); } |
0 |
818 |
bool isValidState() const override { return BS.isValidState(); } |
0 |
| 819 |
|
--- |
819 |
|
--- |
| 820 |
/// See AbstractState::isAtFixpoint(). |
--- |
820 |
/// See AbstractState::isAtFixpoint(). |
--- |
| 821 |
bool isAtFixpoint() const override { return BS.isAtFixpoint(); } |
0 |
821 |
bool isAtFixpoint() const override { return BS.isAtFixpoint(); } |
0 |
| 822 |
|
--- |
822 |
|
--- |
| 823 |
/// See AbstractState::indicateOptimisticFixpoint(). |
--- |
823 |
/// See AbstractState::indicateOptimisticFixpoint(). |
--- |
| 824 |
ChangeStatus indicateOptimisticFixpoint() override { |
0 |
824 |
ChangeStatus indicateOptimisticFixpoint() override { |
0 |
| 825 |
BS.indicateOptimisticFixpoint(); |
0 |
825 |
BS.indicateOptimisticFixpoint(); |
0 |
| 826 |
return ChangeStatus::UNCHANGED; |
0 |
826 |
return ChangeStatus::UNCHANGED; |
0 |
| 827 |
} |
--- |
827 |
} |
--- |
| 828 |
|
--- |
828 |
|
--- |
| 829 |
/// See AbstractState::indicatePessimisticFixpoint(). |
--- |
829 |
/// See AbstractState::indicatePessimisticFixpoint(). |
--- |
| 830 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
830 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
| 831 |
BS.indicatePessimisticFixpoint(); |
0 |
831 |
BS.indicatePessimisticFixpoint(); |
0 |
| 832 |
return ChangeStatus::CHANGED; |
0 |
832 |
return ChangeStatus::CHANGED; |
0 |
| 833 |
} |
--- |
833 |
} |
--- |
| 834 |
|
--- |
834 |
|
--- |
| 835 |
State &operator=(const State &R) { |
--- |
835 |
State &operator=(const State &R) { |
--- |
| 836 |
if (this == &R) |
--- |
836 |
if (this == &R) |
--- |
| 837 |
return *this; |
--- |
837 |
return *this; |
--- |
| 838 |
BS = R.BS; |
--- |
838 |
BS = R.BS; |
--- |
| 839 |
AccessList = R.AccessList; |
--- |
839 |
AccessList = R.AccessList; |
--- |
| 840 |
OffsetBins = R.OffsetBins; |
--- |
840 |
OffsetBins = R.OffsetBins; |
--- |
| 841 |
RemoteIMap = R.RemoteIMap; |
--- |
841 |
RemoteIMap = R.RemoteIMap; |
--- |
| 842 |
return *this; |
--- |
842 |
return *this; |
--- |
| 843 |
} |
--- |
843 |
} |
--- |
| 844 |
|
--- |
844 |
|
--- |
| 845 |
State &operator=(State &&R) { |
--- |
845 |
State &operator=(State &&R) { |
--- |
| 846 |
if (this == &R) |
--- |
846 |
if (this == &R) |
--- |
| 847 |
return *this; |
--- |
847 |
return *this; |
--- |
| 848 |
std::swap(BS, R.BS); |
--- |
848 |
std::swap(BS, R.BS); |
--- |
| 849 |
std::swap(AccessList, R.AccessList); |
--- |
849 |
std::swap(AccessList, R.AccessList); |
--- |
| 850 |
std::swap(OffsetBins, R.OffsetBins); |
--- |
850 |
std::swap(OffsetBins, R.OffsetBins); |
--- |
| 851 |
std::swap(RemoteIMap, R.RemoteIMap); |
--- |
851 |
std::swap(RemoteIMap, R.RemoteIMap); |
--- |
| 852 |
return *this; |
--- |
852 |
return *this; |
--- |
| 853 |
} |
--- |
853 |
} |
--- |
| 854 |
|
--- |
854 |
|
--- |
| 855 |
/// Add a new Access to the state at offset \p Offset and with size \p Size. |
--- |
855 |
/// Add a new Access to the state at offset \p Offset and with size \p Size. |
--- |
| 856 |
/// The access is associated with \p I, writes \p Content (if anything), and |
--- |
856 |
/// The access is associated with \p I, writes \p Content (if anything), and |
--- |
| 857 |
/// is of kind \p Kind. If an Access already exists for the same \p I and same |
--- |
857 |
/// is of kind \p Kind. If an Access already exists for the same \p I and same |
--- |
| 858 |
/// \p RemoteI, the two are combined, potentially losing information about |
--- |
858 |
/// \p RemoteI, the two are combined, potentially losing information about |
--- |
| 859 |
/// offset and size. The resulting access must now be moved from its original |
--- |
859 |
/// offset and size. The resulting access must now be moved from its original |
--- |
| 860 |
/// OffsetBin to the bin for its new offset. |
--- |
860 |
/// OffsetBin to the bin for its new offset. |
--- |
| 861 |
/// |
--- |
861 |
/// |
--- |
| 862 |
/// \Returns CHANGED, if the state changed, UNCHANGED otherwise. |
--- |
862 |
/// \Returns CHANGED, if the state changed, UNCHANGED otherwise. |
--- |
| 863 |
ChangeStatus addAccess(Attributor &A, const AAPointerInfo::RangeList &Ranges, |
--- |
863 |
ChangeStatus addAccess(Attributor &A, const AAPointerInfo::RangeList &Ranges, |
--- |
| 864 |
Instruction &I, std::optional Content, |
--- |
864 |
Instruction &I, std::optional Content, |
--- |
| 865 |
AAPointerInfo::AccessKind Kind, Type *Ty, |
--- |
865 |
AAPointerInfo::AccessKind Kind, Type *Ty, |
--- |
| 866 |
Instruction *RemoteI = nullptr); |
--- |
866 |
Instruction *RemoteI = nullptr); |
--- |
| 867 |
|
--- |
867 |
|
--- |
| 868 |
using OffsetBinsTy = DenseMap>; |
--- |
868 |
using OffsetBinsTy = DenseMap>; |
--- |
| 869 |
|
--- |
869 |
|
--- |
| 870 |
using const_bin_iterator = OffsetBinsTy::const_iterator; |
--- |
870 |
using const_bin_iterator = OffsetBinsTy::const_iterator; |
--- |
| 871 |
const_bin_iterator begin() const { return OffsetBins.begin(); } |
0 |
871 |
const_bin_iterator begin() const { return OffsetBins.begin(); } |
0 |
| 872 |
const_bin_iterator end() const { return OffsetBins.end(); } |
0 |
872 |
const_bin_iterator end() const { return OffsetBins.end(); } |
0 |
| 873 |
|
--- |
873 |
|
--- |
| 874 |
const AAPointerInfo::Access &getAccess(unsigned Index) const { |
0 |
874 |
const AAPointerInfo::Access &getAccess(unsigned Index) const { |
0 |
| 875 |
return AccessList[Index]; |
0 |
875 |
return AccessList[Index]; |
0 |
| 876 |
} |
--- |
876 |
} |
--- |
| 877 |
|
--- |
877 |
|
--- |
| 878 |
protected: |
--- |
878 |
protected: |
--- |
| 879 |
// Every memory instruction results in an Access object. We maintain a list of |
--- |
879 |
// Every memory instruction results in an Access object. We maintain a list of |
--- |
| 880 |
// all Access objects that we own, along with the following maps: |
--- |
880 |
// all Access objects that we own, along with the following maps: |
--- |
| 881 |
// |
--- |
881 |
// |
--- |
| 882 |
// - OffsetBins: RangeTy -> { Access } |
--- |
882 |
// - OffsetBins: RangeTy -> { Access } |
--- |
| 883 |
// - RemoteIMap: RemoteI x LocalI -> Access |
--- |
883 |
// - RemoteIMap: RemoteI x LocalI -> Access |
--- |
| 884 |
// |
--- |
884 |
// |
--- |
| 885 |
// A RemoteI is any instruction that accesses memory. RemoteI is different |
--- |
885 |
// A RemoteI is any instruction that accesses memory. RemoteI is different |
--- |
| 886 |
// from LocalI if and only if LocalI is a call; then RemoteI is some |
--- |
886 |
// from LocalI if and only if LocalI is a call; then RemoteI is some |
--- |
| 887 |
// instruction in the callgraph starting from LocalI. Multiple paths in the |
--- |
887 |
// instruction in the callgraph starting from LocalI. Multiple paths in the |
--- |
| 888 |
// callgraph from LocalI to RemoteI may produce multiple accesses, but these |
--- |
888 |
// callgraph from LocalI to RemoteI may produce multiple accesses, but these |
--- |
| 889 |
// are all combined into a single Access object. This may result in loss of |
--- |
889 |
// are all combined into a single Access object. This may result in loss of |
--- |
| 890 |
// information in RangeTy in the Access object. |
--- |
890 |
// information in RangeTy in the Access object. |
--- |
| 891 |
SmallVector AccessList; |
--- |
891 |
SmallVector AccessList; |
--- |
| 892 |
OffsetBinsTy OffsetBins; |
--- |
892 |
OffsetBinsTy OffsetBins; |
--- |
| 893 |
DenseMap> RemoteIMap; |
--- |
893 |
DenseMap> RemoteIMap; |
--- |
| 894 |
|
--- |
894 |
|
--- |
| 895 |
/// See AAPointerInfo::forallInterferingAccesses. |
--- |
895 |
/// See AAPointerInfo::forallInterferingAccesses. |
--- |
| 896 |
bool forallInterferingAccesses( |
0 |
896 |
bool forallInterferingAccesses( |
0 |
| 897 |
AA::RangeTy Range, |
--- |
897 |
AA::RangeTy Range, |
--- |
| 898 |
function_ref CB) const { |
--- |
898 |
function_ref CB) const { |
--- |
| 899 |
if (!isValidState()) |
0 |
899 |
if (!isValidState()) |
0 |
| 900 |
return false; |
0 |
900 |
return false; |
0 |
| 901 |
|
--- |
901 |
|
--- |
| 902 |
for (const auto &It : OffsetBins) { |
0 |
902 |
for (const auto &It : OffsetBins) { |
0 |
| 903 |
AA::RangeTy ItRange = It.getFirst(); |
0 |
903 |
AA::RangeTy ItRange = It.getFirst(); |
0 |
| 904 |
if (!Range.mayOverlap(ItRange)) |
0 |
904 |
if (!Range.mayOverlap(ItRange)) |
0 |
| 905 |
continue; |
0 |
905 |
continue; |
0 |
| 906 |
bool IsExact = Range == ItRange && !Range.offsetOrSizeAreUnknown(); |
0 |
906 |
bool IsExact = Range == ItRange && !Range.offsetOrSizeAreUnknown(); |
0 |
| 907 |
for (auto Index : It.getSecond()) { |
0 |
907 |
for (auto Index : It.getSecond()) { |
0 |
| 908 |
auto &Access = AccessList[Index]; |
0 |
908 |
auto &Access = AccessList[Index]; |
0 |
| 909 |
if (!CB(Access, IsExact)) |
0 |
909 |
if (!CB(Access, IsExact)) |
0 |
| 910 |
return false; |
0 |
910 |
return false; |
0 |
| 911 |
} |
0 |
911 |
} |
0 |
| 912 |
} |
--- |
912 |
} |
--- |
| 913 |
return true; |
0 |
913 |
return true; |
0 |
| 914 |
} |
--- |
914 |
} |
--- |
| 915 |
|
--- |
915 |
|
--- |
| 916 |
/// See AAPointerInfo::forallInterferingAccesses. |
--- |
916 |
/// See AAPointerInfo::forallInterferingAccesses. |
--- |
| 917 |
bool forallInterferingAccesses( |
0 |
917 |
bool forallInterferingAccesses( |
0 |
| 918 |
Instruction &I, |
--- |
918 |
Instruction &I, |
--- |
| 919 |
function_ref CB, |
--- |
919 |
function_ref CB, |
--- |
| 920 |
AA::RangeTy &Range) const { |
--- |
920 |
AA::RangeTy &Range) const { |
--- |
| 921 |
if (!isValidState()) |
0 |
921 |
if (!isValidState()) |
0 |
| 922 |
return false; |
0 |
922 |
return false; |
0 |
| 923 |
|
--- |
923 |
|
--- |
| 924 |
auto LocalList = RemoteIMap.find(&I); |
0 |
924 |
auto LocalList = RemoteIMap.find(&I); |
0 |
| 925 |
if (LocalList == RemoteIMap.end()) { |
0 |
925 |
if (LocalList == RemoteIMap.end()) { |
0 |
| 926 |
return true; |
0 |
926 |
return true; |
0 |
| 927 |
} |
--- |
927 |
} |
--- |
| 928 |
|
--- |
928 |
|
--- |
| 929 |
for (unsigned Index : LocalList->getSecond()) { |
0 |
929 |
for (unsigned Index : LocalList->getSecond()) { |
0 |
| 930 |
for (auto &R : AccessList[Index]) { |
0 |
930 |
for (auto &R : AccessList[Index]) { |
0 |
| 931 |
Range &= R; |
0 |
931 |
Range &= R; |
0 |
| 932 |
if (Range.offsetAndSizeAreUnknown()) |
0 |
932 |
if (Range.offsetAndSizeAreUnknown()) |
0 |
| 933 |
break; |
0 |
933 |
break; |
0 |
| 934 |
} |
--- |
934 |
} |
--- |
| 935 |
} |
--- |
935 |
} |
--- |
| 936 |
return forallInterferingAccesses(Range, CB); |
0 |
936 |
return forallInterferingAccesses(Range, CB); |
0 |
| 937 |
} |
--- |
937 |
} |
--- |
| 938 |
|
--- |
938 |
|
--- |
| 939 |
private: |
--- |
939 |
private: |
--- |
| 940 |
/// State to track fixpoint and validity. |
--- |
940 |
/// State to track fixpoint and validity. |
--- |
| 941 |
BooleanState BS; |
--- |
941 |
BooleanState BS; |
--- |
| 942 |
}; |
--- |
942 |
}; |
--- |
| 943 |
|
--- |
943 |
|
--- |
| 944 |
ChangeStatus AA::PointerInfo::State::addAccess( |
0 |
944 |
ChangeStatus AA::PointerInfo::State::addAccess( |
0 |
| 945 |
Attributor &A, const AAPointerInfo::RangeList &Ranges, Instruction &I, |
--- |
945 |
Attributor &A, const AAPointerInfo::RangeList &Ranges, Instruction &I, |
--- |
| 946 |
std::optional Content, AAPointerInfo::AccessKind Kind, Type *Ty, |
--- |
946 |
std::optional Content, AAPointerInfo::AccessKind Kind, Type *Ty, |
--- |
| 947 |
Instruction *RemoteI) { |
--- |
947 |
Instruction *RemoteI) { |
--- |
| 948 |
RemoteI = RemoteI ? RemoteI : &I; |
0 |
948 |
RemoteI = RemoteI ? RemoteI : &I; |
0 |
| 949 |
|
--- |
949 |
|
--- |
| 950 |
// Check if we have an access for this instruction, if not, simply add it. |
--- |
950 |
// Check if we have an access for this instruction, if not, simply add it. |
--- |
| 951 |
auto &LocalList = RemoteIMap[RemoteI]; |
0 |
951 |
auto &LocalList = RemoteIMap[RemoteI]; |
0 |
| 952 |
bool AccExists = false; |
0 |
952 |
bool AccExists = false; |
0 |
| 953 |
unsigned AccIndex = AccessList.size(); |
0 |
953 |
unsigned AccIndex = AccessList.size(); |
0 |
| 954 |
for (auto Index : LocalList) { |
0 |
954 |
for (auto Index : LocalList) { |
0 |
| 955 |
auto &A = AccessList[Index]; |
0 |
955 |
auto &A = AccessList[Index]; |
0 |
| 956 |
if (A.getLocalInst() == &I) { |
0 |
956 |
if (A.getLocalInst() == &I) { |
0 |
| 957 |
AccExists = true; |
0 |
957 |
AccExists = true; |
0 |
| 958 |
AccIndex = Index; |
0 |
958 |
AccIndex = Index; |
0 |
| 959 |
break; |
0 |
959 |
break; |
0 |
| 960 |
} |
--- |
960 |
} |
--- |
| 961 |
} |
--- |
961 |
} |
--- |
| 962 |
|
--- |
962 |
|
--- |
| 963 |
auto AddToBins = [&](const AAPointerInfo::RangeList &ToAdd) { |
0 |
963 |
auto AddToBins = [&](const AAPointerInfo::RangeList &ToAdd) { |
0 |
| 964 |
LLVM_DEBUG(if (ToAdd.size()) dbgs() |
0 |
964 |
LLVM_DEBUG(if (ToAdd.size()) dbgs() |
0 |
| 965 |
<< "[AAPointerInfo] Inserting access in new offset bins\n";); |
--- |
965 |
<< "[AAPointerInfo] Inserting access in new offset bins\n";); |
--- |
| 966 |
|
--- |
966 |
|
--- |
| 967 |
for (auto Key : ToAdd) { |
0 |
967 |
for (auto Key : ToAdd) { |
0 |
| 968 |
LLVM_DEBUG(dbgs() << " key " << Key << "\n"); |
0 |
968 |
LLVM_DEBUG(dbgs() << " key " << Key << "\n"); |
0 |
| 969 |
OffsetBins[Key].insert(AccIndex); |
0 |
969 |
OffsetBins[Key].insert(AccIndex); |
0 |
| 970 |
} |
--- |
970 |
} |
--- |
| 971 |
}; |
0 |
971 |
}; |
0 |
| 972 |
|
--- |
972 |
|
--- |
| 973 |
if (!AccExists) { |
0 |
973 |
if (!AccExists) { |
0 |
| 974 |
AccessList.emplace_back(&I, RemoteI, Ranges, Content, Kind, Ty); |
0 |
974 |
AccessList.emplace_back(&I, RemoteI, Ranges, Content, Kind, Ty); |
0 |
| 975 |
assert((AccessList.size() == AccIndex + 1) && |
0 |
975 |
assert((AccessList.size() == AccIndex + 1) && |
0 |
| 976 |
"New Access should have been at AccIndex"); |
--- |
976 |
"New Access should have been at AccIndex"); |
--- |
| 977 |
LocalList.push_back(AccIndex); |
0 |
977 |
LocalList.push_back(AccIndex); |
0 |
| 978 |
AddToBins(AccessList[AccIndex].getRanges()); |
0 |
978 |
AddToBins(AccessList[AccIndex].getRanges()); |
0 |
| 979 |
return ChangeStatus::CHANGED; |
0 |
979 |
return ChangeStatus::CHANGED; |
0 |
| 980 |
} |
--- |
980 |
} |
--- |
| 981 |
|
--- |
981 |
|
--- |
| 982 |
// Combine the new Access with the existing Access, and then update the |
--- |
982 |
// Combine the new Access with the existing Access, and then update the |
--- |
| 983 |
// mapping in the offset bins. |
--- |
983 |
// mapping in the offset bins. |
--- |
| 984 |
AAPointerInfo::Access Acc(&I, RemoteI, Ranges, Content, Kind, Ty); |
0 |
984 |
AAPointerInfo::Access Acc(&I, RemoteI, Ranges, Content, Kind, Ty); |
0 |
| 985 |
auto &Current = AccessList[AccIndex]; |
0 |
985 |
auto &Current = AccessList[AccIndex]; |
0 |
| 986 |
auto Before = Current; |
0 |
986 |
auto Before = Current; |
0 |
| 987 |
Current &= Acc; |
0 |
987 |
Current &= Acc; |
0 |
| 988 |
if (Current == Before) |
0 |
988 |
if (Current == Before) |
0 |
| 989 |
return ChangeStatus::UNCHANGED; |
0 |
989 |
return ChangeStatus::UNCHANGED; |
0 |
| 990 |
|
--- |
990 |
|
--- |
| 991 |
auto &ExistingRanges = Before.getRanges(); |
0 |
991 |
auto &ExistingRanges = Before.getRanges(); |
0 |
| 992 |
auto &NewRanges = Current.getRanges(); |
0 |
992 |
auto &NewRanges = Current.getRanges(); |
0 |
| 993 |
|
--- |
993 |
|
--- |
| 994 |
// Ranges that are in the old access but not the new access need to be removed |
--- |
994 |
// Ranges that are in the old access but not the new access need to be removed |
--- |
| 995 |
// from the offset bins. |
--- |
995 |
// from the offset bins. |
--- |
| 996 |
AAPointerInfo::RangeList ToRemove; |
0 |
996 |
AAPointerInfo::RangeList ToRemove; |
0 |
| 997 |
AAPointerInfo::RangeList::set_difference(ExistingRanges, NewRanges, ToRemove); |
0 |
997 |
AAPointerInfo::RangeList::set_difference(ExistingRanges, NewRanges, ToRemove); |
0 |
| 998 |
LLVM_DEBUG(if (ToRemove.size()) dbgs() |
0 |
998 |
LLVM_DEBUG(if (ToRemove.size()) dbgs() |
0 |
| 999 |
<< "[AAPointerInfo] Removing access from old offset bins\n";); |
--- |
999 |
<< "[AAPointerInfo] Removing access from old offset bins\n";); |
--- |
| 1000 |
|
--- |
1000 |
|
--- |
| 1001 |
for (auto Key : ToRemove) { |
0 |
1001 |
for (auto Key : ToRemove) { |
0 |
| 1002 |
LLVM_DEBUG(dbgs() << " key " << Key << "\n"); |
0 |
1002 |
LLVM_DEBUG(dbgs() << " key " << Key << "\n"); |
0 |
| 1003 |
assert(OffsetBins.count(Key) && "Existing Access must be in some bin."); |
0 |
1003 |
assert(OffsetBins.count(Key) && "Existing Access must be in some bin."); |
0 |
| 1004 |
auto &Bin = OffsetBins[Key]; |
0 |
1004 |
auto &Bin = OffsetBins[Key]; |
0 |
| 1005 |
assert(Bin.count(AccIndex) && |
0 |
1005 |
assert(Bin.count(AccIndex) && |
0 |
| 1006 |
"Expected bin to actually contain the Access."); |
--- |
1006 |
"Expected bin to actually contain the Access."); |
--- |
| 1007 |
Bin.erase(AccIndex); |
0 |
1007 |
Bin.erase(AccIndex); |
0 |
| 1008 |
} |
--- |
1008 |
} |
--- |
| 1009 |
|
--- |
1009 |
|
--- |
| 1010 |
// Ranges that are in the new access but not the old access need to be added |
--- |
1010 |
// Ranges that are in the new access but not the old access need to be added |
--- |
| 1011 |
// to the offset bins. |
--- |
1011 |
// to the offset bins. |
--- |
| 1012 |
AAPointerInfo::RangeList ToAdd; |
0 |
1012 |
AAPointerInfo::RangeList ToAdd; |
0 |
| 1013 |
AAPointerInfo::RangeList::set_difference(NewRanges, ExistingRanges, ToAdd); |
0 |
1013 |
AAPointerInfo::RangeList::set_difference(NewRanges, ExistingRanges, ToAdd); |
0 |
| 1014 |
AddToBins(ToAdd); |
0 |
1014 |
AddToBins(ToAdd); |
0 |
| 1015 |
return ChangeStatus::CHANGED; |
0 |
1015 |
return ChangeStatus::CHANGED; |
0 |
| 1016 |
} |
0 |
1016 |
} |
0 |
| 1017 |
|
--- |
1017 |
|
--- |
| 1018 |
namespace { |
--- |
1018 |
namespace { |
--- |
| 1019 |
|
--- |
1019 |
|
--- |
| 1020 |
/// A helper containing a list of offsets computed for a Use. Ideally this |
--- |
1020 |
/// A helper containing a list of offsets computed for a Use. Ideally this |
--- |
| 1021 |
/// list should be strictly ascending, but we ensure that only when we |
--- |
1021 |
/// list should be strictly ascending, but we ensure that only when we |
--- |
| 1022 |
/// actually translate the list of offsets to a RangeList. |
--- |
1022 |
/// actually translate the list of offsets to a RangeList. |
--- |
| 1023 |
struct OffsetInfo { |
--- |
1023 |
struct OffsetInfo { |
--- |
| 1024 |
using VecTy = SmallVector; |
--- |
1024 |
using VecTy = SmallVector; |
--- |
| 1025 |
using const_iterator = VecTy::const_iterator; |
--- |
1025 |
using const_iterator = VecTy::const_iterator; |
--- |
| 1026 |
VecTy Offsets; |
--- |
1026 |
VecTy Offsets; |
--- |
| 1027 |
|
--- |
1027 |
|
--- |
| 1028 |
const_iterator begin() const { return Offsets.begin(); } |
0 |
1028 |
const_iterator begin() const { return Offsets.begin(); } |
0 |
| 1029 |
const_iterator end() const { return Offsets.end(); } |
0 |
1029 |
const_iterator end() const { return Offsets.end(); } |
0 |
| 1030 |
|
--- |
1030 |
|
--- |
| 1031 |
bool operator==(const OffsetInfo &RHS) const { |
0 |
1031 |
bool operator==(const OffsetInfo &RHS) const { |
0 |
| 1032 |
return Offsets == RHS.Offsets; |
0 |
1032 |
return Offsets == RHS.Offsets; |
0 |
| 1033 |
} |
--- |
1033 |
} |
--- |
| 1034 |
|
--- |
1034 |
|
--- |
| 1035 |
bool operator!=(const OffsetInfo &RHS) const { return !(*this == RHS); } |
--- |
1035 |
bool operator!=(const OffsetInfo &RHS) const { return !(*this == RHS); } |
--- |
| 1036 |
|
--- |
1036 |
|
--- |
| 1037 |
void insert(int64_t Offset) { Offsets.push_back(Offset); } |
0 |
1037 |
void insert(int64_t Offset) { Offsets.push_back(Offset); } |
0 |
| 1038 |
bool isUnassigned() const { return Offsets.size() == 0; } |
0 |
1038 |
bool isUnassigned() const { return Offsets.size() == 0; } |
0 |
| 1039 |
|
--- |
1039 |
|
--- |
| 1040 |
bool isUnknown() const { |
0 |
1040 |
bool isUnknown() const { |
0 |
| 1041 |
if (isUnassigned()) |
0 |
1041 |
if (isUnassigned()) |
0 |
| 1042 |
return false; |
0 |
1042 |
return false; |
0 |
| 1043 |
if (Offsets.size() == 1) |
0 |
1043 |
if (Offsets.size() == 1) |
0 |
| 1044 |
return Offsets.front() == AA::RangeTy::Unknown; |
0 |
1044 |
return Offsets.front() == AA::RangeTy::Unknown; |
0 |
| 1045 |
return false; |
0 |
1045 |
return false; |
0 |
| 1046 |
} |
--- |
1046 |
} |
--- |
| 1047 |
|
--- |
1047 |
|
--- |
| 1048 |
void setUnknown() { |
0 |
1048 |
void setUnknown() { |
0 |
| 1049 |
Offsets.clear(); |
0 |
1049 |
Offsets.clear(); |
0 |
| 1050 |
Offsets.push_back(AA::RangeTy::Unknown); |
0 |
1050 |
Offsets.push_back(AA::RangeTy::Unknown); |
0 |
| 1051 |
} |
0 |
1051 |
} |
0 |
| 1052 |
|
--- |
1052 |
|
--- |
| 1053 |
void addToAll(int64_t Inc) { |
0 |
1053 |
void addToAll(int64_t Inc) { |
0 |
| 1054 |
for (auto &Offset : Offsets) { |
0 |
1054 |
for (auto &Offset : Offsets) { |
0 |
| 1055 |
Offset += Inc; |
0 |
1055 |
Offset += Inc; |
0 |
| 1056 |
} |
--- |
1056 |
} |
--- |
| 1057 |
} |
0 |
1057 |
} |
0 |
| 1058 |
|
--- |
1058 |
|
--- |
| 1059 |
/// Copy offsets from \p R into the current list. |
--- |
1059 |
/// Copy offsets from \p R into the current list. |
--- |
| 1060 |
/// |
--- |
1060 |
/// |
--- |
| 1061 |
/// Ideally all lists should be strictly ascending, but we defer that to the |
--- |
1061 |
/// Ideally all lists should be strictly ascending, but we defer that to the |
--- |
| 1062 |
/// actual use of the list. So we just blindly append here. |
--- |
1062 |
/// actual use of the list. So we just blindly append here. |
--- |
| 1063 |
void merge(const OffsetInfo &R) { Offsets.append(R.Offsets); } |
0 |
1063 |
void merge(const OffsetInfo &R) { Offsets.append(R.Offsets); } |
0 |
| 1064 |
}; |
--- |
1064 |
}; |
--- |
| 1065 |
|
--- |
1065 |
|
--- |
| 1066 |
#ifndef NDEBUG |
--- |
1066 |
#ifndef NDEBUG |
--- |
| 1067 |
static raw_ostream &operator<<(raw_ostream &OS, const OffsetInfo &OI) { |
0 |
1067 |
static raw_ostream &operator<<(raw_ostream &OS, const OffsetInfo &OI) { |
0 |
| 1068 |
ListSeparator LS; |
0 |
1068 |
ListSeparator LS; |
0 |
| 1069 |
OS << "["; |
0 |
1069 |
OS << "["; |
0 |
| 1070 |
for (auto Offset : OI) { |
0 |
1070 |
for (auto Offset : OI) { |
0 |
| 1071 |
OS << LS << Offset; |
0 |
1071 |
OS << LS << Offset; |
0 |
| 1072 |
} |
--- |
1072 |
} |
--- |
| 1073 |
OS << "]"; |
0 |
1073 |
OS << "]"; |
0 |
| 1074 |
return OS; |
0 |
1074 |
return OS; |
0 |
| 1075 |
} |
--- |
1075 |
} |
--- |
| 1076 |
#endif // NDEBUG |
--- |
1076 |
#endif // NDEBUG |
--- |
| 1077 |
|
--- |
1077 |
|
--- |
| 1078 |
struct AAPointerInfoImpl |
--- |
1078 |
struct AAPointerInfoImpl |
--- |
| 1079 |
: public StateWrapper { |
--- |
1079 |
: public StateWrapper { |
--- |
| 1080 |
using BaseTy = StateWrapper; |
--- |
1080 |
using BaseTy = StateWrapper; |
--- |
| 1081 |
AAPointerInfoImpl(const IRPosition &IRP, Attributor &A) : BaseTy(IRP) {} |
0 |
1081 |
AAPointerInfoImpl(const IRPosition &IRP, Attributor &A) : BaseTy(IRP) {} |
0 |
| 1082 |
|
--- |
1082 |
|
--- |
| 1083 |
/// See AbstractAttribute::getAsStr(). |
--- |
1083 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 1084 |
const std::string getAsStr(Attributor *A) const override { |
0 |
1084 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 1085 |
return std::string("PointerInfo ") + |
0 |
1085 |
return std::string("PointerInfo ") + |
0 |
| 1086 |
(isValidState() ? (std::string("#") + |
0 |
1086 |
(isValidState() ? (std::string("#") + |
0 |
| 1087 |
std::to_string(OffsetBins.size()) + " bins") |
0 |
1087 |
std::to_string(OffsetBins.size()) + " bins") |
0 |
| 1088 |
: ""); |
0 |
1088 |
: ""); |
0 |
| 1089 |
} |
--- |
1089 |
} |
--- |
| 1090 |
|
--- |
1090 |
|
--- |
| 1091 |
/// See AbstractAttribute::manifest(...). |
--- |
1091 |
/// See AbstractAttribute::manifest(...). |
--- |
| 1092 |
ChangeStatus manifest(Attributor &A) override { |
0 |
1092 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 1093 |
return AAPointerInfo::manifest(A); |
0 |
1093 |
return AAPointerInfo::manifest(A); |
0 |
| 1094 |
} |
--- |
1094 |
} |
--- |
| 1095 |
|
--- |
1095 |
|
--- |
| 1096 |
bool forallInterferingAccesses( |
0 |
1096 |
bool forallInterferingAccesses( |
0 |
| 1097 |
AA::RangeTy Range, |
--- |
1097 |
AA::RangeTy Range, |
--- |
| 1098 |
function_ref CB) |
--- |
1098 |
function_ref CB) |
--- |
| 1099 |
const override { |
--- |
1099 |
const override { |
--- |
| 1100 |
return State::forallInterferingAccesses(Range, CB); |
0 |
1100 |
return State::forallInterferingAccesses(Range, CB); |
0 |
| 1101 |
} |
--- |
1101 |
} |
--- |
| 1102 |
|
--- |
1102 |
|
--- |
| 1103 |
bool forallInterferingAccesses( |
0 |
1103 |
bool forallInterferingAccesses( |
0 |
| 1104 |
Attributor &A, const AbstractAttribute &QueryingAA, Instruction &I, |
--- |
1104 |
Attributor &A, const AbstractAttribute &QueryingAA, Instruction &I, |
--- |
| 1105 |
bool FindInterferingWrites, bool FindInterferingReads, |
--- |
1105 |
bool FindInterferingWrites, bool FindInterferingReads, |
--- |
| 1106 |
function_ref UserCB, bool &HasBeenWrittenTo, |
--- |
1106 |
function_ref UserCB, bool &HasBeenWrittenTo, |
--- |
| 1107 |
AA::RangeTy &Range) const override { |
--- |
1107 |
AA::RangeTy &Range) const override { |
--- |
| 1108 |
HasBeenWrittenTo = false; |
0 |
1108 |
HasBeenWrittenTo = false; |
0 |
| 1109 |
|
--- |
1109 |
|
--- |
| 1110 |
SmallPtrSet DominatingWrites; |
0 |
1110 |
SmallPtrSet DominatingWrites; |
0 |
| 1111 |
SmallVector, 8> InterferingAccesses; |
0 |
1111 |
SmallVector, 8> InterferingAccesses; |
0 |
| 1112 |
|
--- |
1112 |
|
--- |
| 1113 |
Function &Scope = *I.getFunction(); |
0 |
1113 |
Function &Scope = *I.getFunction(); |
0 |
| 1114 |
bool IsKnownNoSync; |
--- |
1114 |
bool IsKnownNoSync; |
--- |
| 1115 |
bool IsAssumedNoSync = AA::hasAssumedIRAttr( |
0 |
1115 |
bool IsAssumedNoSync = AA::hasAssumedIRAttr( |
0 |
| 1116 |
A, &QueryingAA, IRPosition::function(Scope), DepClassTy::OPTIONAL, |
0 |
1116 |
A, &QueryingAA, IRPosition::function(Scope), DepClassTy::OPTIONAL, |
0 |
| 1117 |
IsKnownNoSync); |
--- |
1117 |
IsKnownNoSync); |
--- |
| 1118 |
const auto *ExecDomainAA = A.lookupAAFor( |
0 |
1118 |
const auto *ExecDomainAA = A.lookupAAFor( |
0 |
| 1119 |
IRPosition::function(Scope), &QueryingAA, DepClassTy::NONE); |
0 |
1119 |
IRPosition::function(Scope), &QueryingAA, DepClassTy::NONE); |
0 |
| 1120 |
bool AllInSameNoSyncFn = IsAssumedNoSync; |
0 |
1120 |
bool AllInSameNoSyncFn = IsAssumedNoSync; |
0 |
| 1121 |
bool InstIsExecutedByInitialThreadOnly = |
--- |
1121 |
bool InstIsExecutedByInitialThreadOnly = |
--- |
| 1122 |
ExecDomainAA && ExecDomainAA->isExecutedByInitialThreadOnly(I); |
0 |
1122 |
ExecDomainAA && ExecDomainAA->isExecutedByInitialThreadOnly(I); |
0 |
| 1123 |
|
--- |
1123 |
|
--- |
| 1124 |
// If the function is not ending in aligned barriers, we need the stores to |
--- |
1124 |
// If the function is not ending in aligned barriers, we need the stores to |
--- |
| 1125 |
// be in aligned barriers. The load being in one is not sufficient since the |
--- |
1125 |
// be in aligned barriers. The load being in one is not sufficient since the |
--- |
| 1126 |
// store might be executed by a thread that disappears after, causing the |
--- |
1126 |
// store might be executed by a thread that disappears after, causing the |
--- |
| 1127 |
// aligned barrier guarding the load to unblock and the load to read a value |
--- |
1127 |
// aligned barrier guarding the load to unblock and the load to read a value |
--- |
| 1128 |
// that has no CFG path to the load. |
--- |
1128 |
// that has no CFG path to the load. |
--- |
| 1129 |
bool InstIsExecutedInAlignedRegion = |
--- |
1129 |
bool InstIsExecutedInAlignedRegion = |
--- |
| 1130 |
FindInterferingReads && ExecDomainAA && |
0 |
1130 |
FindInterferingReads && ExecDomainAA && |
0 |
| 1131 |
ExecDomainAA->isExecutedInAlignedRegion(A, I); |
0 |
1131 |
ExecDomainAA->isExecutedInAlignedRegion(A, I); |
0 |
| 1132 |
|
--- |
1132 |
|
--- |
| 1133 |
if (InstIsExecutedInAlignedRegion || InstIsExecutedByInitialThreadOnly) |
0 |
1133 |
if (InstIsExecutedInAlignedRegion || InstIsExecutedByInitialThreadOnly) |
0 |
| 1134 |
A.recordDependence(*ExecDomainAA, QueryingAA, DepClassTy::OPTIONAL); |
0 |
1134 |
A.recordDependence(*ExecDomainAA, QueryingAA, DepClassTy::OPTIONAL); |
0 |
| 1135 |
|
--- |
1135 |
|
--- |
| 1136 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
1136 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
| 1137 |
bool IsThreadLocalObj = |
--- |
1137 |
bool IsThreadLocalObj = |
--- |
| 1138 |
AA::isAssumedThreadLocalObject(A, getAssociatedValue(), *this); |
0 |
1138 |
AA::isAssumedThreadLocalObject(A, getAssociatedValue(), *this); |
0 |
| 1139 |
|
--- |
1139 |
|
--- |
| 1140 |
// Helper to determine if we need to consider threading, which we cannot |
--- |
1140 |
// Helper to determine if we need to consider threading, which we cannot |
--- |
| 1141 |
// right now. However, if the function is (assumed) nosync or the thread |
--- |
1141 |
// right now. However, if the function is (assumed) nosync or the thread |
--- |
| 1142 |
// executing all instructions is the main thread only we can ignore |
--- |
1142 |
// executing all instructions is the main thread only we can ignore |
--- |
| 1143 |
// threading. Also, thread-local objects do not require threading reasoning. |
--- |
1143 |
// threading. Also, thread-local objects do not require threading reasoning. |
--- |
| 1144 |
// Finally, we can ignore threading if either access is executed in an |
--- |
1144 |
// Finally, we can ignore threading if either access is executed in an |
--- |
| 1145 |
// aligned region. |
--- |
1145 |
// aligned region. |
--- |
| 1146 |
auto CanIgnoreThreadingForInst = [&](const Instruction &I) -> bool { |
0 |
1146 |
auto CanIgnoreThreadingForInst = [&](const Instruction &I) -> bool { |
0 |
| 1147 |
if (IsThreadLocalObj || AllInSameNoSyncFn) |
0 |
1147 |
if (IsThreadLocalObj || AllInSameNoSyncFn) |
0 |
| 1148 |
return true; |
0 |
1148 |
return true; |
0 |
| 1149 |
const auto *FnExecDomainAA = |
--- |
1149 |
const auto *FnExecDomainAA = |
--- |
| 1150 |
I.getFunction() == &Scope |
0 |
1150 |
I.getFunction() == &Scope |
0 |
| 1151 |
? ExecDomainAA |
0 |
1151 |
? ExecDomainAA |
0 |
| 1152 |
: A.lookupAAFor( |
0 |
1152 |
: A.lookupAAFor( |
0 |
| 1153 |
IRPosition::function(*I.getFunction()), &QueryingAA, |
0 |
1153 |
IRPosition::function(*I.getFunction()), &QueryingAA, |
0 |
| 1154 |
DepClassTy::NONE); |
0 |
1154 |
DepClassTy::NONE); |
0 |
| 1155 |
if (!FnExecDomainAA) |
0 |
1155 |
if (!FnExecDomainAA) |
0 |
| 1156 |
return false; |
0 |
1156 |
return false; |
0 |
| 1157 |
if (InstIsExecutedInAlignedRegion || |
0 |
1157 |
if (InstIsExecutedInAlignedRegion || |
0 |
| 1158 |
(FindInterferingWrites && |
0 |
1158 |
(FindInterferingWrites && |
0 |
| 1159 |
FnExecDomainAA->isExecutedInAlignedRegion(A, I))) { |
0 |
1159 |
FnExecDomainAA->isExecutedInAlignedRegion(A, I))) { |
0 |
| 1160 |
A.recordDependence(*FnExecDomainAA, QueryingAA, DepClassTy::OPTIONAL); |
0 |
1160 |
A.recordDependence(*FnExecDomainAA, QueryingAA, DepClassTy::OPTIONAL); |
0 |
| 1161 |
return true; |
0 |
1161 |
return true; |
0 |
| 1162 |
} |
--- |
1162 |
} |
--- |
| 1163 |
if (InstIsExecutedByInitialThreadOnly && |
0 |
1163 |
if (InstIsExecutedByInitialThreadOnly && |
0 |
| 1164 |
FnExecDomainAA->isExecutedByInitialThreadOnly(I)) { |
0 |
1164 |
FnExecDomainAA->isExecutedByInitialThreadOnly(I)) { |
0 |
| 1165 |
A.recordDependence(*FnExecDomainAA, QueryingAA, DepClassTy::OPTIONAL); |
0 |
1165 |
A.recordDependence(*FnExecDomainAA, QueryingAA, DepClassTy::OPTIONAL); |
0 |
| 1166 |
return true; |
0 |
1166 |
return true; |
0 |
| 1167 |
} |
--- |
1167 |
} |
--- |
| 1168 |
return false; |
0 |
1168 |
return false; |
0 |
| 1169 |
}; |
0 |
1169 |
}; |
0 |
| 1170 |
|
--- |
1170 |
|
--- |
| 1171 |
// Helper to determine if the access is executed by the same thread as the |
--- |
1171 |
// Helper to determine if the access is executed by the same thread as the |
--- |
| 1172 |
// given instruction, for now it is sufficient to avoid any potential |
--- |
1172 |
// given instruction, for now it is sufficient to avoid any potential |
--- |
| 1173 |
// threading effects as we cannot deal with them anyway. |
--- |
1173 |
// threading effects as we cannot deal with them anyway. |
--- |
| 1174 |
auto CanIgnoreThreading = [&](const Access &Acc) -> bool { |
0 |
1174 |
auto CanIgnoreThreading = [&](const Access &Acc) -> bool { |
0 |
| 1175 |
return CanIgnoreThreadingForInst(*Acc.getRemoteInst()) || |
0 |
1175 |
return CanIgnoreThreadingForInst(*Acc.getRemoteInst()) || |
0 |
| 1176 |
(Acc.getRemoteInst() != Acc.getLocalInst() && |
0 |
1176 |
(Acc.getRemoteInst() != Acc.getLocalInst() && |
0 |
| 1177 |
CanIgnoreThreadingForInst(*Acc.getLocalInst())); |
0 |
1177 |
CanIgnoreThreadingForInst(*Acc.getLocalInst())); |
0 |
| 1178 |
}; |
0 |
1178 |
}; |
0 |
| 1179 |
|
--- |
1179 |
|
--- |
| 1180 |
// TODO: Use inter-procedural reachability and dominance. |
--- |
1180 |
// TODO: Use inter-procedural reachability and dominance. |
--- |
| 1181 |
bool IsKnownNoRecurse; |
--- |
1181 |
bool IsKnownNoRecurse; |
--- |
| 1182 |
AA::hasAssumedIRAttr( |
0 |
1182 |
AA::hasAssumedIRAttr( |
0 |
| 1183 |
A, this, IRPosition::function(Scope), DepClassTy::OPTIONAL, |
0 |
1183 |
A, this, IRPosition::function(Scope), DepClassTy::OPTIONAL, |
0 |
| 1184 |
IsKnownNoRecurse); |
--- |
1184 |
IsKnownNoRecurse); |
--- |
| 1185 |
|
--- |
1185 |
|
--- |
| 1186 |
const bool UseDominanceReasoning = |
0 |
1186 |
const bool UseDominanceReasoning = |
0 |
| 1187 |
FindInterferingWrites && IsKnownNoRecurse; |
0 |
1187 |
FindInterferingWrites && IsKnownNoRecurse; |
0 |
| 1188 |
const DominatorTree *DT = |
--- |
1188 |
const DominatorTree *DT = |
--- |
| 1189 |
InfoCache.getAnalysisResultForFunction(Scope); |
0 |
1189 |
InfoCache.getAnalysisResultForFunction(Scope); |
0 |
| 1190 |
|
--- |
1190 |
|
--- |
| 1191 |
// Helper to check if a value has "kernel lifetime", that is it will not |
--- |
1191 |
// Helper to check if a value has "kernel lifetime", that is it will not |
--- |
| 1192 |
// outlive a GPU kernel. This is true for shared, constant, and local |
--- |
1192 |
// outlive a GPU kernel. This is true for shared, constant, and local |
--- |
| 1193 |
// globals on AMD and NVIDIA GPUs. |
--- |
1193 |
// globals on AMD and NVIDIA GPUs. |
--- |
| 1194 |
auto HasKernelLifetime = [&](Value *V, Module &M) { |
0 |
1194 |
auto HasKernelLifetime = [&](Value *V, Module &M) { |
0 |
| 1195 |
if (!AA::isGPU(M)) |
0 |
1195 |
if (!AA::isGPU(M)) |
0 |
| 1196 |
return false; |
0 |
1196 |
return false; |
0 |
| 1197 |
switch (AA::GPUAddressSpace(V->getType()->getPointerAddressSpace())) { |
0 |
1197 |
switch (AA::GPUAddressSpace(V->getType()->getPointerAddressSpace())) { |
0 |
| 1198 |
case AA::GPUAddressSpace::Shared: |
0 |
1198 |
case AA::GPUAddressSpace::Shared: |
0 |
| 1199 |
case AA::GPUAddressSpace::Constant: |
--- |
1199 |
case AA::GPUAddressSpace::Constant: |
--- |
| 1200 |
case AA::GPUAddressSpace::Local: |
--- |
1200 |
case AA::GPUAddressSpace::Local: |
--- |
| 1201 |
return true; |
0 |
1201 |
return true; |
0 |
| 1202 |
default: |
0 |
1202 |
default: |
0 |
| 1203 |
return false; |
0 |
1203 |
return false; |
0 |
| 1204 |
}; |
--- |
1204 |
}; |
--- |
| 1205 |
}; |
--- |
1205 |
}; |
--- |
| 1206 |
|
--- |
1206 |
|
--- |
| 1207 |
// The IsLiveInCalleeCB will be used by the AA::isPotentiallyReachable query |
--- |
1207 |
// The IsLiveInCalleeCB will be used by the AA::isPotentiallyReachable query |
--- |
| 1208 |
// to determine if we should look at reachability from the callee. For |
--- |
1208 |
// to determine if we should look at reachability from the callee. For |
--- |
| 1209 |
// certain pointers we know the lifetime and we do not have to step into the |
--- |
1209 |
// certain pointers we know the lifetime and we do not have to step into the |
--- |
| 1210 |
// callee to determine reachability as the pointer would be dead in the |
--- |
1210 |
// callee to determine reachability as the pointer would be dead in the |
--- |
| 1211 |
// callee. See the conditional initialization below. |
--- |
1211 |
// callee. See the conditional initialization below. |
--- |
| 1212 |
std::function IsLiveInCalleeCB; |
0 |
1212 |
std::function IsLiveInCalleeCB; |
0 |
| 1213 |
|
--- |
1213 |
|
--- |
| 1214 |
if (auto *AI = dyn_cast(&getAssociatedValue())) { |
0 |
1214 |
if (auto *AI = dyn_cast(&getAssociatedValue())) { |
0 |
| 1215 |
// If the alloca containing function is not recursive the alloca |
--- |
1215 |
// If the alloca containing function is not recursive the alloca |
--- |
| 1216 |
// must be dead in the callee. |
--- |
1216 |
// must be dead in the callee. |
--- |
| 1217 |
const Function *AIFn = AI->getFunction(); |
0 |
1217 |
const Function *AIFn = AI->getFunction(); |
0 |
| 1218 |
bool IsKnownNoRecurse; |
--- |
1218 |
bool IsKnownNoRecurse; |
--- |
| 1219 |
if (AA::hasAssumedIRAttr( |
0 |
1219 |
if (AA::hasAssumedIRAttr( |
0 |
| 1220 |
A, this, IRPosition::function(*AIFn), DepClassTy::OPTIONAL, |
0 |
1220 |
A, this, IRPosition::function(*AIFn), DepClassTy::OPTIONAL, |
0 |
| 1221 |
IsKnownNoRecurse)) { |
--- |
1221 |
IsKnownNoRecurse)) { |
--- |
| 1222 |
IsLiveInCalleeCB = [AIFn](const Function &Fn) { return AIFn != &Fn; }; |
0 |
1222 |
IsLiveInCalleeCB = [AIFn](const Function &Fn) { return AIFn != &Fn; }; |
0 |
| 1223 |
} |
--- |
1223 |
} |
--- |
| 1224 |
} else if (auto *GV = dyn_cast(&getAssociatedValue())) { |
0 |
1224 |
} else if (auto *GV = dyn_cast(&getAssociatedValue())) { |
0 |
| 1225 |
// If the global has kernel lifetime we can stop if we reach a kernel |
--- |
1225 |
// If the global has kernel lifetime we can stop if we reach a kernel |
--- |
| 1226 |
// as it is "dead" in the (unknown) callees. |
--- |
1226 |
// as it is "dead" in the (unknown) callees. |
--- |
| 1227 |
if (HasKernelLifetime(GV, *GV->getParent())) |
0 |
1227 |
if (HasKernelLifetime(GV, *GV->getParent())) |
0 |
| 1228 |
IsLiveInCalleeCB = [](const Function &Fn) { |
0 |
1228 |
IsLiveInCalleeCB = [](const Function &Fn) { |
0 |
| 1229 |
return !Fn.hasFnAttribute("kernel"); |
0 |
1229 |
return !Fn.hasFnAttribute("kernel"); |
0 |
| 1230 |
}; |
0 |
1230 |
}; |
0 |
| 1231 |
} |
--- |
1231 |
} |
--- |
| 1232 |
|
--- |
1232 |
|
--- |
| 1233 |
// Set of accesses/instructions that will overwrite the result and are |
--- |
1233 |
// Set of accesses/instructions that will overwrite the result and are |
--- |
| 1234 |
// therefore blockers in the reachability traversal. |
--- |
1234 |
// therefore blockers in the reachability traversal. |
--- |
| 1235 |
AA::InstExclusionSetTy ExclusionSet; |
0 |
1235 |
AA::InstExclusionSetTy ExclusionSet; |
0 |
| 1236 |
|
--- |
1236 |
|
--- |
| 1237 |
auto AccessCB = [&](const Access &Acc, bool Exact) { |
0 |
1237 |
auto AccessCB = [&](const Access &Acc, bool Exact) { |
0 |
| 1238 |
if (Exact && Acc.isMustAccess() && Acc.getRemoteInst() != &I) { |
0 |
1238 |
if (Exact && Acc.isMustAccess() && Acc.getRemoteInst() != &I) { |
0 |
| 1239 |
if (Acc.isWrite() || (isa(I) && Acc.isWriteOrAssumption())) |
0 |
1239 |
if (Acc.isWrite() || (isa(I) && Acc.isWriteOrAssumption())) |
0 |
| 1240 |
ExclusionSet.insert(Acc.getRemoteInst()); |
0 |
1240 |
ExclusionSet.insert(Acc.getRemoteInst()); |
0 |
| 1241 |
} |
--- |
1241 |
} |
--- |
| 1242 |
|
--- |
1242 |
|
--- |
| 1243 |
if ((!FindInterferingWrites || !Acc.isWriteOrAssumption()) && |
0 |
1243 |
if ((!FindInterferingWrites || !Acc.isWriteOrAssumption()) && |
0 |
| 1244 |
(!FindInterferingReads || !Acc.isRead())) |
0 |
1244 |
(!FindInterferingReads || !Acc.isRead())) |
0 |
| 1245 |
return true; |
0 |
1245 |
return true; |
0 |
| 1246 |
|
--- |
1246 |
|
--- |
| 1247 |
bool Dominates = FindInterferingWrites && DT && Exact && |
0 |
1247 |
bool Dominates = FindInterferingWrites && DT && Exact && |
0 |
| 1248 |
Acc.isMustAccess() && |
0 |
1248 |
Acc.isMustAccess() && |
0 |
| 1249 |
(Acc.getRemoteInst()->getFunction() == &Scope) && |
0 |
1249 |
(Acc.getRemoteInst()->getFunction() == &Scope) && |
0 |
| 1250 |
DT->dominates(Acc.getRemoteInst(), &I); |
0 |
1250 |
DT->dominates(Acc.getRemoteInst(), &I); |
0 |
| 1251 |
if (Dominates) |
0 |
1251 |
if (Dominates) |
0 |
| 1252 |
DominatingWrites.insert(&Acc); |
0 |
1252 |
DominatingWrites.insert(&Acc); |
0 |
| 1253 |
|
--- |
1253 |
|
--- |
| 1254 |
// Track if all interesting accesses are in the same `nosync` function as |
--- |
1254 |
// Track if all interesting accesses are in the same `nosync` function as |
--- |
| 1255 |
// the given instruction. |
--- |
1255 |
// the given instruction. |
--- |
| 1256 |
AllInSameNoSyncFn &= Acc.getRemoteInst()->getFunction() == &Scope; |
0 |
1256 |
AllInSameNoSyncFn &= Acc.getRemoteInst()->getFunction() == &Scope; |
0 |
| 1257 |
|
--- |
1257 |
|
--- |
| 1258 |
InterferingAccesses.push_back({&Acc, Exact}); |
0 |
1258 |
InterferingAccesses.push_back({&Acc, Exact}); |
0 |
| 1259 |
return true; |
0 |
1259 |
return true; |
0 |
| 1260 |
}; |
0 |
1260 |
}; |
0 |
| 1261 |
if (!State::forallInterferingAccesses(I, AccessCB, Range)) |
0 |
1261 |
if (!State::forallInterferingAccesses(I, AccessCB, Range)) |
0 |
| 1262 |
return false; |
0 |
1262 |
return false; |
0 |
| 1263 |
|
--- |
1263 |
|
--- |
| 1264 |
HasBeenWrittenTo = !DominatingWrites.empty(); |
0 |
1264 |
HasBeenWrittenTo = !DominatingWrites.empty(); |
0 |
| 1265 |
|
--- |
1265 |
|
--- |
| 1266 |
// Dominating writes form a chain, find the least/lowest member. |
--- |
1266 |
// Dominating writes form a chain, find the least/lowest member. |
--- |
| 1267 |
Instruction *LeastDominatingWriteInst = nullptr; |
0 |
1267 |
Instruction *LeastDominatingWriteInst = nullptr; |
0 |
| 1268 |
for (const Access *Acc : DominatingWrites) { |
0 |
1268 |
for (const Access *Acc : DominatingWrites) { |
0 |
| 1269 |
if (!LeastDominatingWriteInst) { |
0 |
1269 |
if (!LeastDominatingWriteInst) { |
0 |
| 1270 |
LeastDominatingWriteInst = Acc->getRemoteInst(); |
0 |
1270 |
LeastDominatingWriteInst = Acc->getRemoteInst(); |
0 |
| 1271 |
} else if (DT->dominates(LeastDominatingWriteInst, |
0 |
1271 |
} else if (DT->dominates(LeastDominatingWriteInst, |
0 |
| 1272 |
Acc->getRemoteInst())) { |
0 |
1272 |
Acc->getRemoteInst())) { |
0 |
| 1273 |
LeastDominatingWriteInst = Acc->getRemoteInst(); |
0 |
1273 |
LeastDominatingWriteInst = Acc->getRemoteInst(); |
0 |
| 1274 |
} |
--- |
1274 |
} |
--- |
| 1275 |
} |
--- |
1275 |
} |
--- |
| 1276 |
|
--- |
1276 |
|
--- |
| 1277 |
// Helper to determine if we can skip a specific write access. |
--- |
1277 |
// Helper to determine if we can skip a specific write access. |
--- |
| 1278 |
auto CanSkipAccess = [&](const Access &Acc, bool Exact) { |
0 |
1278 |
auto CanSkipAccess = [&](const Access &Acc, bool Exact) { |
0 |
| 1279 |
if (!CanIgnoreThreading(Acc)) |
0 |
1279 |
if (!CanIgnoreThreading(Acc)) |
0 |
| 1280 |
return false; |
0 |
1280 |
return false; |
0 |
| 1281 |
|
--- |
1281 |
|
--- |
| 1282 |
// Check read (RAW) dependences and write (WAR) dependences as necessary. |
--- |
1282 |
// Check read (RAW) dependences and write (WAR) dependences as necessary. |
--- |
| 1283 |
// If we successfully excluded all effects we are interested in, the |
--- |
1283 |
// If we successfully excluded all effects we are interested in, the |
--- |
| 1284 |
// access can be skipped. |
--- |
1284 |
// access can be skipped. |
--- |
| 1285 |
bool ReadChecked = !FindInterferingReads; |
0 |
1285 |
bool ReadChecked = !FindInterferingReads; |
0 |
| 1286 |
bool WriteChecked = !FindInterferingWrites; |
0 |
1286 |
bool WriteChecked = !FindInterferingWrites; |
0 |
| 1287 |
|
--- |
1287 |
|
--- |
| 1288 |
// If the instruction cannot reach the access, the former does not |
--- |
1288 |
// If the instruction cannot reach the access, the former does not |
--- |
| 1289 |
// interfere with what the access reads. |
--- |
1289 |
// interfere with what the access reads. |
--- |
| 1290 |
if (!ReadChecked) { |
0 |
1290 |
if (!ReadChecked) { |
0 |
| 1291 |
if (!AA::isPotentiallyReachable(A, I, *Acc.getRemoteInst(), QueryingAA, |
0 |
1291 |
if (!AA::isPotentiallyReachable(A, I, *Acc.getRemoteInst(), QueryingAA, |
0 |
| 1292 |
&ExclusionSet, IsLiveInCalleeCB)) |
0 |
1292 |
&ExclusionSet, IsLiveInCalleeCB)) |
0 |
| 1293 |
ReadChecked = true; |
0 |
1293 |
ReadChecked = true; |
0 |
| 1294 |
} |
--- |
1294 |
} |
--- |
| 1295 |
// If the instruction cannot be reach from the access, the latter does not |
--- |
1295 |
// If the instruction cannot be reach from the access, the latter does not |
--- |
| 1296 |
// interfere with what the instruction reads. |
--- |
1296 |
// interfere with what the instruction reads. |
--- |
| 1297 |
if (!WriteChecked) { |
0 |
1297 |
if (!WriteChecked) { |
0 |
| 1298 |
if (!AA::isPotentiallyReachable(A, *Acc.getRemoteInst(), I, QueryingAA, |
0 |
1298 |
if (!AA::isPotentiallyReachable(A, *Acc.getRemoteInst(), I, QueryingAA, |
0 |
| 1299 |
&ExclusionSet, IsLiveInCalleeCB)) |
--- |
1299 |
&ExclusionSet, IsLiveInCalleeCB)) |
--- |
| 1300 |
WriteChecked = true; |
0 |
1300 |
WriteChecked = true; |
0 |
| 1301 |
} |
--- |
1301 |
} |
--- |
| 1302 |
|
--- |
1302 |
|
--- |
| 1303 |
// If we still might be affected by the write of the access but there are |
--- |
1303 |
// If we still might be affected by the write of the access but there are |
--- |
| 1304 |
// dominating writes in the function of the instruction |
--- |
1304 |
// dominating writes in the function of the instruction |
--- |
| 1305 |
// (HasBeenWrittenTo), we can try to reason that the access is overwritten |
--- |
1305 |
// (HasBeenWrittenTo), we can try to reason that the access is overwritten |
--- |
| 1306 |
// by them. This would have happend above if they are all in the same |
--- |
1306 |
// by them. This would have happend above if they are all in the same |
--- |
| 1307 |
// function, so we only check the inter-procedural case. Effectively, we |
--- |
1307 |
// function, so we only check the inter-procedural case. Effectively, we |
--- |
| 1308 |
// want to show that there is no call after the dominting write that might |
--- |
1308 |
// want to show that there is no call after the dominting write that might |
--- |
| 1309 |
// reach the access, and when it returns reach the instruction with the |
--- |
1309 |
// reach the access, and when it returns reach the instruction with the |
--- |
| 1310 |
// updated value. To this end, we iterate all call sites, check if they |
--- |
1310 |
// updated value. To this end, we iterate all call sites, check if they |
--- |
| 1311 |
// might reach the instruction without going through another access |
--- |
1311 |
// might reach the instruction without going through another access |
--- |
| 1312 |
// (ExclusionSet) and at the same time might reach the access. However, |
--- |
1312 |
// (ExclusionSet) and at the same time might reach the access. However, |
--- |
| 1313 |
// that is all part of AAInterFnReachability. |
--- |
1313 |
// that is all part of AAInterFnReachability. |
--- |
| 1314 |
if (!WriteChecked && HasBeenWrittenTo && |
0 |
1314 |
if (!WriteChecked && HasBeenWrittenTo && |
0 |
| 1315 |
Acc.getRemoteInst()->getFunction() != &Scope) { |
0 |
1315 |
Acc.getRemoteInst()->getFunction() != &Scope) { |
0 |
| 1316 |
|
--- |
1316 |
|
--- |
| 1317 |
const auto *FnReachabilityAA = A.getAAFor( |
0 |
1317 |
const auto *FnReachabilityAA = A.getAAFor( |
0 |
| 1318 |
QueryingAA, IRPosition::function(Scope), DepClassTy::OPTIONAL); |
0 |
1318 |
QueryingAA, IRPosition::function(Scope), DepClassTy::OPTIONAL); |
0 |
| 1319 |
|
--- |
1319 |
|
--- |
| 1320 |
// Without going backwards in the call tree, can we reach the access |
--- |
1320 |
// Without going backwards in the call tree, can we reach the access |
--- |
| 1321 |
// from the least dominating write. Do not allow to pass the instruction |
--- |
1321 |
// from the least dominating write. Do not allow to pass the instruction |
--- |
| 1322 |
// itself either. |
--- |
1322 |
// itself either. |
--- |
| 1323 |
bool Inserted = ExclusionSet.insert(&I).second; |
0 |
1323 |
bool Inserted = ExclusionSet.insert(&I).second; |
0 |
| 1324 |
|
--- |
1324 |
|
--- |
| 1325 |
if (!FnReachabilityAA || |
0 |
1325 |
if (!FnReachabilityAA || |
0 |
| 1326 |
!FnReachabilityAA->instructionCanReach( |
0 |
1326 |
!FnReachabilityAA->instructionCanReach( |
0 |
| 1327 |
A, *LeastDominatingWriteInst, |
0 |
1327 |
A, *LeastDominatingWriteInst, |
0 |
| 1328 |
*Acc.getRemoteInst()->getFunction(), &ExclusionSet)) |
0 |
1328 |
*Acc.getRemoteInst()->getFunction(), &ExclusionSet)) |
0 |
| 1329 |
WriteChecked = true; |
0 |
1329 |
WriteChecked = true; |
0 |
| 1330 |
|
--- |
1330 |
|
--- |
| 1331 |
if (Inserted) |
0 |
1331 |
if (Inserted) |
0 |
| 1332 |
ExclusionSet.erase(&I); |
0 |
1332 |
ExclusionSet.erase(&I); |
0 |
| 1333 |
} |
--- |
1333 |
} |
--- |
| 1334 |
|
--- |
1334 |
|
--- |
| 1335 |
if (ReadChecked && WriteChecked) |
0 |
1335 |
if (ReadChecked && WriteChecked) |
0 |
| 1336 |
return true; |
0 |
1336 |
return true; |
0 |
| 1337 |
|
--- |
1337 |
|
--- |
| 1338 |
if (!DT || !UseDominanceReasoning) |
0 |
1338 |
if (!DT || !UseDominanceReasoning) |
0 |
| 1339 |
return false; |
0 |
1339 |
return false; |
0 |
| 1340 |
if (!DominatingWrites.count(&Acc)) |
0 |
1340 |
if (!DominatingWrites.count(&Acc)) |
0 |
| 1341 |
return false; |
0 |
1341 |
return false; |
0 |
| 1342 |
return LeastDominatingWriteInst != Acc.getRemoteInst(); |
0 |
1342 |
return LeastDominatingWriteInst != Acc.getRemoteInst(); |
0 |
| 1343 |
}; |
0 |
1343 |
}; |
0 |
| 1344 |
|
--- |
1344 |
|
--- |
| 1345 |
// Run the user callback on all accesses we cannot skip and return if |
--- |
1345 |
// Run the user callback on all accesses we cannot skip and return if |
--- |
| 1346 |
// that succeeded for all or not. |
--- |
1346 |
// that succeeded for all or not. |
--- |
| 1347 |
for (auto &It : InterferingAccesses) { |
0 |
1347 |
for (auto &It : InterferingAccesses) { |
0 |
| 1348 |
if ((!AllInSameNoSyncFn && !IsThreadLocalObj && !ExecDomainAA) || |
0 |
1348 |
if ((!AllInSameNoSyncFn && !IsThreadLocalObj && !ExecDomainAA) || |
0 |
| 1349 |
!CanSkipAccess(*It.first, It.second)) { |
0 |
1349 |
!CanSkipAccess(*It.first, It.second)) { |
0 |
| 1350 |
if (!UserCB(*It.first, It.second)) |
0 |
1350 |
if (!UserCB(*It.first, It.second)) |
0 |
| 1351 |
return false; |
0 |
1351 |
return false; |
0 |
| 1352 |
} |
--- |
1352 |
} |
--- |
| 1353 |
} |
--- |
1353 |
} |
--- |
| 1354 |
return true; |
0 |
1354 |
return true; |
0 |
| 1355 |
} |
0 |
1355 |
} |
0 |
| 1356 |
|
--- |
1356 |
|
--- |
| 1357 |
ChangeStatus translateAndAddStateFromCallee(Attributor &A, |
0 |
1357 |
ChangeStatus translateAndAddStateFromCallee(Attributor &A, |
0 |
| 1358 |
const AAPointerInfo &OtherAA, |
--- |
1358 |
const AAPointerInfo &OtherAA, |
--- |
| 1359 |
CallBase &CB) { |
--- |
1359 |
CallBase &CB) { |
--- |
| 1360 |
using namespace AA::PointerInfo; |
--- |
1360 |
using namespace AA::PointerInfo; |
--- |
| 1361 |
if (!OtherAA.getState().isValidState() || !isValidState()) |
0 |
1361 |
if (!OtherAA.getState().isValidState() || !isValidState()) |
0 |
| 1362 |
return indicatePessimisticFixpoint(); |
0 |
1362 |
return indicatePessimisticFixpoint(); |
0 |
| 1363 |
|
--- |
1363 |
|
--- |
| 1364 |
const auto &OtherAAImpl = static_cast(OtherAA); |
0 |
1364 |
const auto &OtherAAImpl = static_cast(OtherAA); |
0 |
| 1365 |
bool IsByval = OtherAAImpl.getAssociatedArgument()->hasByValAttr(); |
0 |
1365 |
bool IsByval = OtherAAImpl.getAssociatedArgument()->hasByValAttr(); |
0 |
| 1366 |
|
--- |
1366 |
|
--- |
| 1367 |
// Combine the accesses bin by bin. |
--- |
1367 |
// Combine the accesses bin by bin. |
--- |
| 1368 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
1368 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 1369 |
const auto &State = OtherAAImpl.getState(); |
0 |
1369 |
const auto &State = OtherAAImpl.getState(); |
0 |
| 1370 |
for (const auto &It : State) { |
0 |
1370 |
for (const auto &It : State) { |
0 |
| 1371 |
for (auto Index : It.getSecond()) { |
0 |
1371 |
for (auto Index : It.getSecond()) { |
0 |
| 1372 |
const auto &RAcc = State.getAccess(Index); |
0 |
1372 |
const auto &RAcc = State.getAccess(Index); |
0 |
| 1373 |
if (IsByval && !RAcc.isRead()) |
0 |
1373 |
if (IsByval && !RAcc.isRead()) |
0 |
| 1374 |
continue; |
0 |
1374 |
continue; |
0 |
| 1375 |
bool UsedAssumedInformation = false; |
0 |
1375 |
bool UsedAssumedInformation = false; |
0 |
| 1376 |
AccessKind AK = RAcc.getKind(); |
0 |
1376 |
AccessKind AK = RAcc.getKind(); |
0 |
| 1377 |
auto Content = A.translateArgumentToCallSiteContent( |
0 |
1377 |
auto Content = A.translateArgumentToCallSiteContent( |
0 |
| 1378 |
RAcc.getContent(), CB, *this, UsedAssumedInformation); |
--- |
1378 |
RAcc.getContent(), CB, *this, UsedAssumedInformation); |
--- |
| 1379 |
AK = AccessKind(AK & (IsByval ? AccessKind::AK_R : AccessKind::AK_RW)); |
0 |
1379 |
AK = AccessKind(AK & (IsByval ? AccessKind::AK_R : AccessKind::AK_RW)); |
0 |
| 1380 |
AK = AccessKind(AK | (RAcc.isMayAccess() ? AK_MAY : AK_MUST)); |
0 |
1380 |
AK = AccessKind(AK | (RAcc.isMayAccess() ? AK_MAY : AK_MUST)); |
0 |
| 1381 |
|
--- |
1381 |
|
--- |
| 1382 |
Changed |= addAccess(A, RAcc.getRanges(), CB, Content, AK, |
--- |
1382 |
Changed |= addAccess(A, RAcc.getRanges(), CB, Content, AK, |
--- |
| 1383 |
RAcc.getType(), RAcc.getRemoteInst()); |
0 |
1383 |
RAcc.getType(), RAcc.getRemoteInst()); |
0 |
| 1384 |
} |
0 |
1384 |
} |
0 |
| 1385 |
} |
--- |
1385 |
} |
--- |
| 1386 |
return Changed; |
0 |
1386 |
return Changed; |
0 |
| 1387 |
} |
--- |
1387 |
} |
--- |
| 1388 |
|
--- |
1388 |
|
--- |
| 1389 |
ChangeStatus translateAndAddState(Attributor &A, const AAPointerInfo &OtherAA, |
0 |
1389 |
ChangeStatus translateAndAddState(Attributor &A, const AAPointerInfo &OtherAA, |
0 |
| 1390 |
const OffsetInfo &Offsets, CallBase &CB) { |
--- |
1390 |
const OffsetInfo &Offsets, CallBase &CB) { |
--- |
| 1391 |
using namespace AA::PointerInfo; |
--- |
1391 |
using namespace AA::PointerInfo; |
--- |
| 1392 |
if (!OtherAA.getState().isValidState() || !isValidState()) |
0 |
1392 |
if (!OtherAA.getState().isValidState() || !isValidState()) |
0 |
| 1393 |
return indicatePessimisticFixpoint(); |
0 |
1393 |
return indicatePessimisticFixpoint(); |
0 |
| 1394 |
|
--- |
1394 |
|
--- |
| 1395 |
const auto &OtherAAImpl = static_cast(OtherAA); |
0 |
1395 |
const auto &OtherAAImpl = static_cast(OtherAA); |
0 |
| 1396 |
|
--- |
1396 |
|
--- |
| 1397 |
// Combine the accesses bin by bin. |
--- |
1397 |
// Combine the accesses bin by bin. |
--- |
| 1398 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
1398 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 1399 |
const auto &State = OtherAAImpl.getState(); |
0 |
1399 |
const auto &State = OtherAAImpl.getState(); |
0 |
| 1400 |
for (const auto &It : State) { |
0 |
1400 |
for (const auto &It : State) { |
0 |
| 1401 |
for (auto Index : It.getSecond()) { |
0 |
1401 |
for (auto Index : It.getSecond()) { |
0 |
| 1402 |
const auto &RAcc = State.getAccess(Index); |
0 |
1402 |
const auto &RAcc = State.getAccess(Index); |
0 |
| 1403 |
for (auto Offset : Offsets) { |
0 |
1403 |
for (auto Offset : Offsets) { |
0 |
| 1404 |
auto NewRanges = Offset == AA::RangeTy::Unknown |
--- |
1404 |
auto NewRanges = Offset == AA::RangeTy::Unknown |
--- |
| 1405 |
? AA::RangeTy::getUnknown() |
0 |
1405 |
? AA::RangeTy::getUnknown() |
0 |
| 1406 |
: RAcc.getRanges(); |
0 |
1406 |
: RAcc.getRanges(); |
0 |
| 1407 |
if (!NewRanges.isUnknown()) { |
0 |
1407 |
if (!NewRanges.isUnknown()) { |
0 |
| 1408 |
NewRanges.addToAllOffsets(Offset); |
0 |
1408 |
NewRanges.addToAllOffsets(Offset); |
0 |
| 1409 |
} |
--- |
1409 |
} |
--- |
| 1410 |
Changed |= |
--- |
1410 |
Changed |= |
--- |
| 1411 |
addAccess(A, NewRanges, CB, RAcc.getContent(), RAcc.getKind(), |
--- |
1411 |
addAccess(A, NewRanges, CB, RAcc.getContent(), RAcc.getKind(), |
--- |
| 1412 |
RAcc.getType(), RAcc.getRemoteInst()); |
0 |
1412 |
RAcc.getType(), RAcc.getRemoteInst()); |
0 |
| 1413 |
} |
0 |
1413 |
} |
0 |
| 1414 |
} |
0 |
1414 |
} |
0 |
| 1415 |
} |
--- |
1415 |
} |
--- |
| 1416 |
return Changed; |
0 |
1416 |
return Changed; |
0 |
| 1417 |
} |
--- |
1417 |
} |
--- |
| 1418 |
|
--- |
1418 |
|
--- |
| 1419 |
/// Statistic tracking for all AAPointerInfo implementations. |
--- |
1419 |
/// Statistic tracking for all AAPointerInfo implementations. |
--- |
| 1420 |
/// See AbstractAttribute::trackStatistics(). |
--- |
1420 |
/// See AbstractAttribute::trackStatistics(). |
--- |
| 1421 |
void trackPointerInfoStatistics(const IRPosition &IRP) const {} |
0 |
1421 |
void trackPointerInfoStatistics(const IRPosition &IRP) const {} |
0 |
| 1422 |
|
--- |
1422 |
|
--- |
| 1423 |
/// Dump the state into \p O. |
--- |
1423 |
/// Dump the state into \p O. |
--- |
| 1424 |
void dumpState(raw_ostream &O) { |
0 |
1424 |
void dumpState(raw_ostream &O) { |
0 |
| 1425 |
for (auto &It : OffsetBins) { |
0 |
1425 |
for (auto &It : OffsetBins) { |
0 |
| 1426 |
O << "[" << It.first.Offset << "-" << It.first.Offset + It.first.Size |
0 |
1426 |
O << "[" << It.first.Offset << "-" << It.first.Offset + It.first.Size |
0 |
| 1427 |
<< "] : " << It.getSecond().size() << "\n"; |
0 |
1427 |
<< "] : " << It.getSecond().size() << "\n"; |
0 |
| 1428 |
for (auto AccIndex : It.getSecond()) { |
0 |
1428 |
for (auto AccIndex : It.getSecond()) { |
0 |
| 1429 |
auto &Acc = AccessList[AccIndex]; |
0 |
1429 |
auto &Acc = AccessList[AccIndex]; |
0 |
| 1430 |
O << " - " << Acc.getKind() << " - " << *Acc.getLocalInst() << "\n"; |
0 |
1430 |
O << " - " << Acc.getKind() << " - " << *Acc.getLocalInst() << "\n"; |
0 |
| 1431 |
if (Acc.getLocalInst() != Acc.getRemoteInst()) |
0 |
1431 |
if (Acc.getLocalInst() != Acc.getRemoteInst()) |
0 |
| 1432 |
O << " --> " << *Acc.getRemoteInst() |
0 |
1432 |
O << " --> " << *Acc.getRemoteInst() |
0 |
| 1433 |
<< "\n"; |
0 |
1433 |
<< "\n"; |
0 |
| 1434 |
if (!Acc.isWrittenValueYetUndetermined()) { |
0 |
1434 |
if (!Acc.isWrittenValueYetUndetermined()) { |
0 |
| 1435 |
if (isa_and_nonnull(Acc.getWrittenValue())) |
0 |
1435 |
if (isa_and_nonnull(Acc.getWrittenValue())) |
0 |
| 1436 |
O << " - c: func " << Acc.getWrittenValue()->getName() |
0 |
1436 |
O << " - c: func " << Acc.getWrittenValue()->getName() |
0 |
| 1437 |
<< "\n"; |
0 |
1437 |
<< "\n"; |
0 |
| 1438 |
else if (Acc.getWrittenValue()) |
0 |
1438 |
else if (Acc.getWrittenValue()) |
0 |
| 1439 |
O << " - c: " << *Acc.getWrittenValue() << "\n"; |
0 |
1439 |
O << " - c: " << *Acc.getWrittenValue() << "\n"; |
0 |
| 1440 |
else |
--- |
1440 |
else |
--- |
| 1441 |
O << " - c: \n"; |
0 |
1441 |
O << " - c: \n"; |
0 |
| 1442 |
} |
--- |
1442 |
} |
--- |
| 1443 |
} |
0 |
1443 |
} |
0 |
| 1444 |
} |
--- |
1444 |
} |
--- |
| 1445 |
} |
0 |
1445 |
} |
0 |
| 1446 |
}; |
--- |
1446 |
}; |
--- |
| 1447 |
|
--- |
1447 |
|
--- |
| 1448 |
struct AAPointerInfoFloating : public AAPointerInfoImpl { |
--- |
1448 |
struct AAPointerInfoFloating : public AAPointerInfoImpl { |
--- |
| 1449 |
using AccessKind = AAPointerInfo::AccessKind; |
--- |
1449 |
using AccessKind = AAPointerInfo::AccessKind; |
--- |
| 1450 |
AAPointerInfoFloating(const IRPosition &IRP, Attributor &A) |
0 |
1450 |
AAPointerInfoFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 1451 |
: AAPointerInfoImpl(IRP, A) {} |
0 |
1451 |
: AAPointerInfoImpl(IRP, A) {} |
0 |
| 1452 |
|
--- |
1452 |
|
--- |
| 1453 |
/// Deal with an access and signal if it was handled successfully. |
--- |
1453 |
/// Deal with an access and signal if it was handled successfully. |
--- |
| 1454 |
bool handleAccess(Attributor &A, Instruction &I, |
0 |
1454 |
bool handleAccess(Attributor &A, Instruction &I, |
0 |
| 1455 |
std::optional Content, AccessKind Kind, |
--- |
1455 |
std::optional Content, AccessKind Kind, |
--- |
| 1456 |
SmallVectorImpl &Offsets, ChangeStatus &Changed, |
--- |
1456 |
SmallVectorImpl &Offsets, ChangeStatus &Changed, |
--- |
| 1457 |
Type &Ty) { |
--- |
1457 |
Type &Ty) { |
--- |
| 1458 |
using namespace AA::PointerInfo; |
--- |
1458 |
using namespace AA::PointerInfo; |
--- |
| 1459 |
auto Size = AA::RangeTy::Unknown; |
0 |
1459 |
auto Size = AA::RangeTy::Unknown; |
0 |
| 1460 |
const DataLayout &DL = A.getDataLayout(); |
0 |
1460 |
const DataLayout &DL = A.getDataLayout(); |
0 |
| 1461 |
TypeSize AccessSize = DL.getTypeStoreSize(&Ty); |
0 |
1461 |
TypeSize AccessSize = DL.getTypeStoreSize(&Ty); |
0 |
| 1462 |
if (!AccessSize.isScalable()) |
0 |
1462 |
if (!AccessSize.isScalable()) |
0 |
| 1463 |
Size = AccessSize.getFixedValue(); |
0 |
1463 |
Size = AccessSize.getFixedValue(); |
0 |
| 1464 |
|
--- |
1464 |
|
--- |
| 1465 |
// Make a strictly ascending list of offsets as required by addAccess() |
--- |
1465 |
// Make a strictly ascending list of offsets as required by addAccess() |
--- |
| 1466 |
llvm::sort(Offsets); |
0 |
1466 |
llvm::sort(Offsets); |
0 |
| 1467 |
auto *Last = std::unique(Offsets.begin(), Offsets.end()); |
0 |
1467 |
auto *Last = std::unique(Offsets.begin(), Offsets.end()); |
0 |
| 1468 |
Offsets.erase(Last, Offsets.end()); |
0 |
1468 |
Offsets.erase(Last, Offsets.end()); |
0 |
| 1469 |
|
--- |
1469 |
|
--- |
| 1470 |
VectorType *VT = dyn_cast(&Ty); |
0 |
1470 |
VectorType *VT = dyn_cast(&Ty); |
0 |
| 1471 |
if (!VT || VT->getElementCount().isScalable() || |
0 |
1471 |
if (!VT || VT->getElementCount().isScalable() || |
0 |
| 1472 |
!Content.value_or(nullptr) || !isa(*Content) || |
0 |
1472 |
!Content.value_or(nullptr) || !isa(*Content) || |
0 |
| 1473 |
(*Content)->getType() != VT || |
0 |
1473 |
(*Content)->getType() != VT || |
0 |
| 1474 |
DL.getTypeStoreSize(VT->getElementType()).isScalable()) { |
0 |
1474 |
DL.getTypeStoreSize(VT->getElementType()).isScalable()) { |
0 |
| 1475 |
Changed = Changed | addAccess(A, {Offsets, Size}, I, Content, Kind, &Ty); |
0 |
1475 |
Changed = Changed | addAccess(A, {Offsets, Size}, I, Content, Kind, &Ty); |
0 |
| 1476 |
} else { |
--- |
1476 |
} else { |
--- |
| 1477 |
// Handle vector stores with constant content element-wise. |
--- |
1477 |
// Handle vector stores with constant content element-wise. |
--- |
| 1478 |
// TODO: We could look for the elements or create instructions |
--- |
1478 |
// TODO: We could look for the elements or create instructions |
--- |
| 1479 |
// representing them. |
--- |
1479 |
// representing them. |
--- |
| 1480 |
// TODO: We need to push the Content into the range abstraction |
--- |
1480 |
// TODO: We need to push the Content into the range abstraction |
--- |
| 1481 |
// (AA::RangeTy) to allow different content values for different |
--- |
1481 |
// (AA::RangeTy) to allow different content values for different |
--- |
| 1482 |
// ranges. ranges. Hence, support vectors storing different values. |
--- |
1482 |
// ranges. ranges. Hence, support vectors storing different values. |
--- |
| 1483 |
Type *ElementType = VT->getElementType(); |
0 |
1483 |
Type *ElementType = VT->getElementType(); |
0 |
| 1484 |
int64_t ElementSize = DL.getTypeStoreSize(ElementType).getFixedValue(); |
0 |
1484 |
int64_t ElementSize = DL.getTypeStoreSize(ElementType).getFixedValue(); |
0 |
| 1485 |
auto *ConstContent = cast(*Content); |
0 |
1485 |
auto *ConstContent = cast(*Content); |
0 |
| 1486 |
Type *Int32Ty = Type::getInt32Ty(ElementType->getContext()); |
0 |
1486 |
Type *Int32Ty = Type::getInt32Ty(ElementType->getContext()); |
0 |
| 1487 |
SmallVector ElementOffsets(Offsets.begin(), Offsets.end()); |
0 |
1487 |
SmallVector ElementOffsets(Offsets.begin(), Offsets.end()); |
0 |
| 1488 |
|
--- |
1488 |
|
--- |
| 1489 |
for (int i = 0, e = VT->getElementCount().getFixedValue(); i != e; ++i) { |
0 |
1489 |
for (int i = 0, e = VT->getElementCount().getFixedValue(); i != e; ++i) { |
0 |
| 1490 |
Value *ElementContent = ConstantExpr::getExtractElement( |
0 |
1490 |
Value *ElementContent = ConstantExpr::getExtractElement( |
0 |
| 1491 |
ConstContent, ConstantInt::get(Int32Ty, i)); |
0 |
1491 |
ConstContent, ConstantInt::get(Int32Ty, i)); |
0 |
| 1492 |
|
--- |
1492 |
|
--- |
| 1493 |
// Add the element access. |
--- |
1493 |
// Add the element access. |
--- |
| 1494 |
Changed = Changed | addAccess(A, {ElementOffsets, ElementSize}, I, |
0 |
1494 |
Changed = Changed | addAccess(A, {ElementOffsets, ElementSize}, I, |
0 |
| 1495 |
ElementContent, Kind, ElementType); |
--- |
1495 |
ElementContent, Kind, ElementType); |
--- |
| 1496 |
|
--- |
1496 |
|
--- |
| 1497 |
// Advance the offsets for the next element. |
--- |
1497 |
// Advance the offsets for the next element. |
--- |
| 1498 |
for (auto &ElementOffset : ElementOffsets) |
0 |
1498 |
for (auto &ElementOffset : ElementOffsets) |
0 |
| 1499 |
ElementOffset += ElementSize; |
0 |
1499 |
ElementOffset += ElementSize; |
0 |
| 1500 |
} |
--- |
1500 |
} |
--- |
| 1501 |
} |
0 |
1501 |
} |
0 |
| 1502 |
return true; |
0 |
1502 |
return true; |
0 |
| 1503 |
}; |
--- |
1503 |
}; |
--- |
| 1504 |
|
--- |
1504 |
|
--- |
| 1505 |
/// See AbstractAttribute::updateImpl(...). |
--- |
1505 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 1506 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
1506 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
| 1507 |
|
--- |
1507 |
|
--- |
| 1508 |
/// If the indices to \p GEP can be traced to constants, incorporate all |
--- |
1508 |
/// If the indices to \p GEP can be traced to constants, incorporate all |
--- |
| 1509 |
/// of these into \p UsrOI. |
--- |
1509 |
/// of these into \p UsrOI. |
--- |
| 1510 |
/// |
--- |
1510 |
/// |
--- |
| 1511 |
/// \return true iff \p UsrOI is updated. |
--- |
1511 |
/// \return true iff \p UsrOI is updated. |
--- |
| 1512 |
bool collectConstantsForGEP(Attributor &A, const DataLayout &DL, |
--- |
1512 |
bool collectConstantsForGEP(Attributor &A, const DataLayout &DL, |
--- |
| 1513 |
OffsetInfo &UsrOI, const OffsetInfo &PtrOI, |
--- |
1513 |
OffsetInfo &UsrOI, const OffsetInfo &PtrOI, |
--- |
| 1514 |
const GEPOperator *GEP); |
--- |
1514 |
const GEPOperator *GEP); |
--- |
| 1515 |
|
--- |
1515 |
|
--- |
| 1516 |
/// See AbstractAttribute::trackStatistics() |
--- |
1516 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 1517 |
void trackStatistics() const override { |
0 |
1517 |
void trackStatistics() const override { |
0 |
| 1518 |
AAPointerInfoImpl::trackPointerInfoStatistics(getIRPosition()); |
0 |
1518 |
AAPointerInfoImpl::trackPointerInfoStatistics(getIRPosition()); |
0 |
| 1519 |
} |
0 |
1519 |
} |
0 |
| 1520 |
}; |
--- |
1520 |
}; |
--- |
| 1521 |
|
--- |
1521 |
|
--- |
| 1522 |
bool AAPointerInfoFloating::collectConstantsForGEP(Attributor &A, |
0 |
1522 |
bool AAPointerInfoFloating::collectConstantsForGEP(Attributor &A, |
0 |
| 1523 |
const DataLayout &DL, |
--- |
1523 |
const DataLayout &DL, |
--- |
| 1524 |
OffsetInfo &UsrOI, |
--- |
1524 |
OffsetInfo &UsrOI, |
--- |
| 1525 |
const OffsetInfo &PtrOI, |
--- |
1525 |
const OffsetInfo &PtrOI, |
--- |
| 1526 |
const GEPOperator *GEP) { |
--- |
1526 |
const GEPOperator *GEP) { |
--- |
| 1527 |
unsigned BitWidth = DL.getIndexTypeSizeInBits(GEP->getType()); |
0 |
1527 |
unsigned BitWidth = DL.getIndexTypeSizeInBits(GEP->getType()); |
0 |
| 1528 |
MapVector VariableOffsets; |
0 |
1528 |
MapVector VariableOffsets; |
0 |
| 1529 |
APInt ConstantOffset(BitWidth, 0); |
0 |
1529 |
APInt ConstantOffset(BitWidth, 0); |
0 |
| 1530 |
|
--- |
1530 |
|
--- |
| 1531 |
assert(!UsrOI.isUnknown() && !PtrOI.isUnknown() && |
0 |
1531 |
assert(!UsrOI.isUnknown() && !PtrOI.isUnknown() && |
0 |
| 1532 |
"Don't look for constant values if the offset has already been " |
--- |
1532 |
"Don't look for constant values if the offset has already been " |
--- |
| 1533 |
"determined to be unknown."); |
--- |
1533 |
"determined to be unknown."); |
--- |
| 1534 |
|
--- |
1534 |
|
--- |
| 1535 |
if (!GEP->collectOffset(DL, BitWidth, VariableOffsets, ConstantOffset)) { |
0 |
1535 |
if (!GEP->collectOffset(DL, BitWidth, VariableOffsets, ConstantOffset)) { |
0 |
| 1536 |
UsrOI.setUnknown(); |
0 |
1536 |
UsrOI.setUnknown(); |
0 |
| 1537 |
return true; |
0 |
1537 |
return true; |
0 |
| 1538 |
} |
--- |
1538 |
} |
--- |
| 1539 |
|
--- |
1539 |
|
--- |
| 1540 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] GEP offset is " |
0 |
1540 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] GEP offset is " |
0 |
| 1541 |
<< (VariableOffsets.empty() ? "" : "not") << " constant " |
--- |
1541 |
<< (VariableOffsets.empty() ? "" : "not") << " constant " |
--- |
| 1542 |
<< *GEP << "\n"); |
--- |
1542 |
<< *GEP << "\n"); |
--- |
| 1543 |
|
--- |
1543 |
|
--- |
| 1544 |
auto Union = PtrOI; |
0 |
1544 |
auto Union = PtrOI; |
0 |
| 1545 |
Union.addToAll(ConstantOffset.getSExtValue()); |
0 |
1545 |
Union.addToAll(ConstantOffset.getSExtValue()); |
0 |
| 1546 |
|
--- |
1546 |
|
--- |
| 1547 |
// Each VI in VariableOffsets has a set of potential constant values. Every |
--- |
1547 |
// Each VI in VariableOffsets has a set of potential constant values. Every |
--- |
| 1548 |
// combination of elements, picked one each from these sets, is separately |
--- |
1548 |
// combination of elements, picked one each from these sets, is separately |
--- |
| 1549 |
// added to the original set of offsets, thus resulting in more offsets. |
--- |
1549 |
// added to the original set of offsets, thus resulting in more offsets. |
--- |
| 1550 |
for (const auto &VI : VariableOffsets) { |
0 |
1550 |
for (const auto &VI : VariableOffsets) { |
0 |
| 1551 |
auto *PotentialConstantsAA = A.getAAFor( |
0 |
1551 |
auto *PotentialConstantsAA = A.getAAFor( |
0 |
| 1552 |
*this, IRPosition::value(*VI.first), DepClassTy::OPTIONAL); |
0 |
1552 |
*this, IRPosition::value(*VI.first), DepClassTy::OPTIONAL); |
0 |
| 1553 |
if (!PotentialConstantsAA || !PotentialConstantsAA->isValidState()) { |
0 |
1553 |
if (!PotentialConstantsAA || !PotentialConstantsAA->isValidState()) { |
0 |
| 1554 |
UsrOI.setUnknown(); |
0 |
1554 |
UsrOI.setUnknown(); |
0 |
| 1555 |
return true; |
0 |
1555 |
return true; |
0 |
| 1556 |
} |
--- |
1556 |
} |
--- |
| 1557 |
|
--- |
1557 |
|
--- |
| 1558 |
// UndefValue is treated as a zero, which leaves Union as is. |
--- |
1558 |
// UndefValue is treated as a zero, which leaves Union as is. |
--- |
| 1559 |
if (PotentialConstantsAA->undefIsContained()) |
0 |
1559 |
if (PotentialConstantsAA->undefIsContained()) |
0 |
| 1560 |
continue; |
0 |
1560 |
continue; |
0 |
| 1561 |
|
--- |
1561 |
|
--- |
| 1562 |
// We need at least one constant in every set to compute an actual offset. |
--- |
1562 |
// We need at least one constant in every set to compute an actual offset. |
--- |
| 1563 |
// Otherwise, we end up pessimizing AAPointerInfo by respecting offsets that |
--- |
1563 |
// Otherwise, we end up pessimizing AAPointerInfo by respecting offsets that |
--- |
| 1564 |
// don't actually exist. In other words, the absence of constant values |
--- |
1564 |
// don't actually exist. In other words, the absence of constant values |
--- |
| 1565 |
// implies that the operation can be assumed dead for now. |
--- |
1565 |
// implies that the operation can be assumed dead for now. |
--- |
| 1566 |
auto &AssumedSet = PotentialConstantsAA->getAssumedSet(); |
0 |
1566 |
auto &AssumedSet = PotentialConstantsAA->getAssumedSet(); |
0 |
| 1567 |
if (AssumedSet.empty()) |
0 |
1567 |
if (AssumedSet.empty()) |
0 |
| 1568 |
return false; |
0 |
1568 |
return false; |
0 |
| 1569 |
|
--- |
1569 |
|
--- |
| 1570 |
OffsetInfo Product; |
0 |
1570 |
OffsetInfo Product; |
0 |
| 1571 |
for (const auto &ConstOffset : AssumedSet) { |
0 |
1571 |
for (const auto &ConstOffset : AssumedSet) { |
0 |
| 1572 |
auto CopyPerOffset = Union; |
0 |
1572 |
auto CopyPerOffset = Union; |
0 |
| 1573 |
CopyPerOffset.addToAll(ConstOffset.getSExtValue() * |
0 |
1573 |
CopyPerOffset.addToAll(ConstOffset.getSExtValue() * |
0 |
| 1574 |
VI.second.getZExtValue()); |
0 |
1574 |
VI.second.getZExtValue()); |
0 |
| 1575 |
Product.merge(CopyPerOffset); |
0 |
1575 |
Product.merge(CopyPerOffset); |
0 |
| 1576 |
} |
0 |
1576 |
} |
0 |
| 1577 |
Union = Product; |
0 |
1577 |
Union = Product; |
0 |
| 1578 |
} |
0 |
1578 |
} |
0 |
| 1579 |
|
--- |
1579 |
|
--- |
| 1580 |
UsrOI = std::move(Union); |
0 |
1580 |
UsrOI = std::move(Union); |
0 |
| 1581 |
return true; |
0 |
1581 |
return true; |
0 |
| 1582 |
} |
0 |
1582 |
} |
0 |
| 1583 |
|
--- |
1583 |
|
--- |
| 1584 |
ChangeStatus AAPointerInfoFloating::updateImpl(Attributor &A) { |
0 |
1584 |
ChangeStatus AAPointerInfoFloating::updateImpl(Attributor &A) { |
0 |
| 1585 |
using namespace AA::PointerInfo; |
--- |
1585 |
using namespace AA::PointerInfo; |
--- |
| 1586 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
1586 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 1587 |
const DataLayout &DL = A.getDataLayout(); |
0 |
1587 |
const DataLayout &DL = A.getDataLayout(); |
0 |
| 1588 |
Value &AssociatedValue = getAssociatedValue(); |
0 |
1588 |
Value &AssociatedValue = getAssociatedValue(); |
0 |
| 1589 |
|
--- |
1589 |
|
--- |
| 1590 |
DenseMap OffsetInfoMap; |
0 |
1590 |
DenseMap OffsetInfoMap; |
0 |
| 1591 |
OffsetInfoMap[&AssociatedValue].insert(0); |
0 |
1591 |
OffsetInfoMap[&AssociatedValue].insert(0); |
0 |
| 1592 |
|
--- |
1592 |
|
--- |
| 1593 |
auto HandlePassthroughUser = [&](Value *Usr, Value *CurPtr, bool &Follow) { |
0 |
1593 |
auto HandlePassthroughUser = [&](Value *Usr, Value *CurPtr, bool &Follow) { |
0 |
| 1594 |
// One does not simply walk into a map and assign a reference to a possibly |
--- |
1594 |
// One does not simply walk into a map and assign a reference to a possibly |
--- |
| 1595 |
// new location. That can cause an invalidation before the assignment |
--- |
1595 |
// new location. That can cause an invalidation before the assignment |
--- |
| 1596 |
// happens, like so: |
--- |
1596 |
// happens, like so: |
--- |
| 1597 |
// |
--- |
1597 |
// |
--- |
| 1598 |
// OffsetInfoMap[Usr] = OffsetInfoMap[CurPtr]; /* bad idea! */ |
--- |
1598 |
// OffsetInfoMap[Usr] = OffsetInfoMap[CurPtr]; /* bad idea! */ |
--- |
| 1599 |
// |
--- |
1599 |
// |
--- |
| 1600 |
// The RHS is a reference that may be invalidated by an insertion caused by |
--- |
1600 |
// The RHS is a reference that may be invalidated by an insertion caused by |
--- |
| 1601 |
// the LHS. So we ensure that the side-effect of the LHS happens first. |
--- |
1601 |
// the LHS. So we ensure that the side-effect of the LHS happens first. |
--- |
| 1602 |
auto &UsrOI = OffsetInfoMap[Usr]; |
0 |
1602 |
auto &UsrOI = OffsetInfoMap[Usr]; |
0 |
| 1603 |
auto &PtrOI = OffsetInfoMap[CurPtr]; |
0 |
1603 |
auto &PtrOI = OffsetInfoMap[CurPtr]; |
0 |
| 1604 |
assert(!PtrOI.isUnassigned() && |
0 |
1604 |
assert(!PtrOI.isUnassigned() && |
0 |
| 1605 |
"Cannot pass through if the input Ptr was not visited!"); |
--- |
1605 |
"Cannot pass through if the input Ptr was not visited!"); |
--- |
| 1606 |
UsrOI = PtrOI; |
0 |
1606 |
UsrOI = PtrOI; |
0 |
| 1607 |
Follow = true; |
0 |
1607 |
Follow = true; |
0 |
| 1608 |
return true; |
0 |
1608 |
return true; |
0 |
| 1609 |
}; |
0 |
1609 |
}; |
0 |
| 1610 |
|
--- |
1610 |
|
--- |
| 1611 |
const auto *F = getAnchorScope(); |
0 |
1611 |
const auto *F = getAnchorScope(); |
0 |
| 1612 |
const auto *CI = |
--- |
1612 |
const auto *CI = |
--- |
| 1613 |
F ? A.getInfoCache().getAnalysisResultForFunction(*F) |
0 |
1613 |
F ? A.getInfoCache().getAnalysisResultForFunction(*F) |
0 |
| 1614 |
: nullptr; |
0 |
1614 |
: nullptr; |
0 |
| 1615 |
const auto *TLI = |
--- |
1615 |
const auto *TLI = |
--- |
| 1616 |
F ? A.getInfoCache().getTargetLibraryInfoForFunction(*F) : nullptr; |
0 |
1616 |
F ? A.getInfoCache().getTargetLibraryInfoForFunction(*F) : nullptr; |
0 |
| 1617 |
|
--- |
1617 |
|
--- |
| 1618 |
auto UsePred = [&](const Use &U, bool &Follow) -> bool { |
0 |
1618 |
auto UsePred = [&](const Use &U, bool &Follow) -> bool { |
0 |
| 1619 |
Value *CurPtr = U.get(); |
0 |
1619 |
Value *CurPtr = U.get(); |
0 |
| 1620 |
User *Usr = U.getUser(); |
0 |
1620 |
User *Usr = U.getUser(); |
0 |
| 1621 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Analyze " << *CurPtr << " in " << *Usr |
0 |
1621 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Analyze " << *CurPtr << " in " << *Usr |
0 |
| 1622 |
<< "\n"); |
--- |
1622 |
<< "\n"); |
--- |
| 1623 |
assert(OffsetInfoMap.count(CurPtr) && |
0 |
1623 |
assert(OffsetInfoMap.count(CurPtr) && |
0 |
| 1624 |
"The current pointer offset should have been seeded!"); |
--- |
1624 |
"The current pointer offset should have been seeded!"); |
--- |
| 1625 |
|
--- |
1625 |
|
--- |
| 1626 |
if (ConstantExpr *CE = dyn_cast(Usr)) { |
0 |
1626 |
if (ConstantExpr *CE = dyn_cast(Usr)) { |
0 |
| 1627 |
if (CE->isCast()) |
0 |
1627 |
if (CE->isCast()) |
0 |
| 1628 |
return HandlePassthroughUser(Usr, CurPtr, Follow); |
0 |
1628 |
return HandlePassthroughUser(Usr, CurPtr, Follow); |
0 |
| 1629 |
if (CE->isCompare()) |
0 |
1629 |
if (CE->isCompare()) |
0 |
| 1630 |
return true; |
0 |
1630 |
return true; |
0 |
| 1631 |
if (!isa(CE)) { |
0 |
1631 |
if (!isa(CE)) { |
0 |
| 1632 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Unhandled constant user " << *CE |
0 |
1632 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Unhandled constant user " << *CE |
0 |
| 1633 |
<< "\n"); |
--- |
1633 |
<< "\n"); |
--- |
| 1634 |
return false; |
0 |
1634 |
return false; |
0 |
| 1635 |
} |
--- |
1635 |
} |
--- |
| 1636 |
} |
--- |
1636 |
} |
--- |
| 1637 |
if (auto *GEP = dyn_cast(Usr)) { |
0 |
1637 |
if (auto *GEP = dyn_cast(Usr)) { |
0 |
| 1638 |
// Note the order here, the Usr access might change the map, CurPtr is |
--- |
1638 |
// Note the order here, the Usr access might change the map, CurPtr is |
--- |
| 1639 |
// already in it though. |
--- |
1639 |
// already in it though. |
--- |
| 1640 |
auto &UsrOI = OffsetInfoMap[Usr]; |
0 |
1640 |
auto &UsrOI = OffsetInfoMap[Usr]; |
0 |
| 1641 |
auto &PtrOI = OffsetInfoMap[CurPtr]; |
0 |
1641 |
auto &PtrOI = OffsetInfoMap[CurPtr]; |
0 |
| 1642 |
|
--- |
1642 |
|
--- |
| 1643 |
if (UsrOI.isUnknown()) |
0 |
1643 |
if (UsrOI.isUnknown()) |
0 |
| 1644 |
return true; |
0 |
1644 |
return true; |
0 |
| 1645 |
|
--- |
1645 |
|
--- |
| 1646 |
if (PtrOI.isUnknown()) { |
0 |
1646 |
if (PtrOI.isUnknown()) { |
0 |
| 1647 |
Follow = true; |
0 |
1647 |
Follow = true; |
0 |
| 1648 |
UsrOI.setUnknown(); |
0 |
1648 |
UsrOI.setUnknown(); |
0 |
| 1649 |
return true; |
0 |
1649 |
return true; |
0 |
| 1650 |
} |
--- |
1650 |
} |
--- |
| 1651 |
|
--- |
1651 |
|
--- |
| 1652 |
Follow = collectConstantsForGEP(A, DL, UsrOI, PtrOI, GEP); |
0 |
1652 |
Follow = collectConstantsForGEP(A, DL, UsrOI, PtrOI, GEP); |
0 |
| 1653 |
return true; |
0 |
1653 |
return true; |
0 |
| 1654 |
} |
--- |
1654 |
} |
--- |
| 1655 |
if (isa(Usr)) |
0 |
1655 |
if (isa(Usr)) |
0 |
| 1656 |
return false; |
0 |
1656 |
return false; |
0 |
| 1657 |
if (isa(Usr) || isa(Usr) || isa(Usr)) |
0 |
1657 |
if (isa(Usr) || isa(Usr) || isa(Usr)) |
0 |
| 1658 |
return HandlePassthroughUser(Usr, CurPtr, Follow); |
0 |
1658 |
return HandlePassthroughUser(Usr, CurPtr, Follow); |
0 |
| 1659 |
|
--- |
1659 |
|
--- |
| 1660 |
// For PHIs we need to take care of the recurrence explicitly as the value |
--- |
1660 |
// For PHIs we need to take care of the recurrence explicitly as the value |
--- |
| 1661 |
// might change while we iterate through a loop. For now, we give up if |
--- |
1661 |
// might change while we iterate through a loop. For now, we give up if |
--- |
| 1662 |
// the PHI is not invariant. |
--- |
1662 |
// the PHI is not invariant. |
--- |
| 1663 |
if (isa(Usr)) { |
0 |
1663 |
if (isa(Usr)) { |
0 |
| 1664 |
// Note the order here, the Usr access might change the map, CurPtr is |
--- |
1664 |
// Note the order here, the Usr access might change the map, CurPtr is |
--- |
| 1665 |
// already in it though. |
--- |
1665 |
// already in it though. |
--- |
| 1666 |
bool IsFirstPHIUser = !OffsetInfoMap.count(Usr); |
0 |
1666 |
bool IsFirstPHIUser = !OffsetInfoMap.count(Usr); |
0 |
| 1667 |
auto &UsrOI = OffsetInfoMap[Usr]; |
0 |
1667 |
auto &UsrOI = OffsetInfoMap[Usr]; |
0 |
| 1668 |
auto &PtrOI = OffsetInfoMap[CurPtr]; |
0 |
1668 |
auto &PtrOI = OffsetInfoMap[CurPtr]; |
0 |
| 1669 |
|
--- |
1669 |
|
--- |
| 1670 |
// Check if the PHI operand has already an unknown offset as we can't |
--- |
1670 |
// Check if the PHI operand has already an unknown offset as we can't |
--- |
| 1671 |
// improve on that anymore. |
--- |
1671 |
// improve on that anymore. |
--- |
| 1672 |
if (PtrOI.isUnknown()) { |
0 |
1672 |
if (PtrOI.isUnknown()) { |
0 |
| 1673 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] PHI operand offset unknown " |
0 |
1673 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] PHI operand offset unknown " |
0 |
| 1674 |
<< *CurPtr << " in " << *Usr << "\n"); |
--- |
1674 |
<< *CurPtr << " in " << *Usr << "\n"); |
--- |
| 1675 |
Follow = !UsrOI.isUnknown(); |
0 |
1675 |
Follow = !UsrOI.isUnknown(); |
0 |
| 1676 |
UsrOI.setUnknown(); |
0 |
1676 |
UsrOI.setUnknown(); |
0 |
| 1677 |
return true; |
0 |
1677 |
return true; |
0 |
| 1678 |
} |
--- |
1678 |
} |
--- |
| 1679 |
|
--- |
1679 |
|
--- |
| 1680 |
// Check if the PHI is invariant (so far). |
--- |
1680 |
// Check if the PHI is invariant (so far). |
--- |
| 1681 |
if (UsrOI == PtrOI) { |
0 |
1681 |
if (UsrOI == PtrOI) { |
0 |
| 1682 |
assert(!PtrOI.isUnassigned() && |
0 |
1682 |
assert(!PtrOI.isUnassigned() && |
0 |
| 1683 |
"Cannot assign if the current Ptr was not visited!"); |
--- |
1683 |
"Cannot assign if the current Ptr was not visited!"); |
--- |
| 1684 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] PHI is invariant (so far)"); |
0 |
1684 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] PHI is invariant (so far)"); |
0 |
| 1685 |
return true; |
0 |
1685 |
return true; |
0 |
| 1686 |
} |
--- |
1686 |
} |
--- |
| 1687 |
|
--- |
1687 |
|
--- |
| 1688 |
// Check if the PHI operand can be traced back to AssociatedValue. |
--- |
1688 |
// Check if the PHI operand can be traced back to AssociatedValue. |
--- |
| 1689 |
APInt Offset( |
--- |
1689 |
APInt Offset( |
--- |
| 1690 |
DL.getIndexSizeInBits(CurPtr->getType()->getPointerAddressSpace()), |
--- |
1690 |
DL.getIndexSizeInBits(CurPtr->getType()->getPointerAddressSpace()), |
--- |
| 1691 |
0); |
0 |
1691 |
0); |
0 |
| 1692 |
Value *CurPtrBase = CurPtr->stripAndAccumulateConstantOffsets( |
0 |
1692 |
Value *CurPtrBase = CurPtr->stripAndAccumulateConstantOffsets( |
0 |
| 1693 |
DL, Offset, /* AllowNonInbounds */ true); |
--- |
1693 |
DL, Offset, /* AllowNonInbounds */ true); |
--- |
| 1694 |
auto It = OffsetInfoMap.find(CurPtrBase); |
0 |
1694 |
auto It = OffsetInfoMap.find(CurPtrBase); |
0 |
| 1695 |
if (It == OffsetInfoMap.end()) { |
0 |
1695 |
if (It == OffsetInfoMap.end()) { |
0 |
| 1696 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] PHI operand is too complex " |
0 |
1696 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] PHI operand is too complex " |
0 |
| 1697 |
<< *CurPtr << " in " << *Usr << "\n"); |
--- |
1697 |
<< *CurPtr << " in " << *Usr << "\n"); |
--- |
| 1698 |
UsrOI.setUnknown(); |
0 |
1698 |
UsrOI.setUnknown(); |
0 |
| 1699 |
Follow = true; |
0 |
1699 |
Follow = true; |
0 |
| 1700 |
return true; |
0 |
1700 |
return true; |
0 |
| 1701 |
} |
--- |
1701 |
} |
--- |
| 1702 |
|
--- |
1702 |
|
--- |
| 1703 |
// Check if the PHI operand is not dependent on the PHI itself. Every |
--- |
1703 |
// Check if the PHI operand is not dependent on the PHI itself. Every |
--- |
| 1704 |
// recurrence is a cyclic net of PHIs in the data flow, and has an |
--- |
1704 |
// recurrence is a cyclic net of PHIs in the data flow, and has an |
--- |
| 1705 |
// equivalent Cycle in the control flow. One of those PHIs must be in the |
--- |
1705 |
// equivalent Cycle in the control flow. One of those PHIs must be in the |
--- |
| 1706 |
// header of that control flow Cycle. This is independent of the choice of |
--- |
1706 |
// header of that control flow Cycle. This is independent of the choice of |
--- |
| 1707 |
// Cycles reported by CycleInfo. It is sufficient to check the PHIs in |
--- |
1707 |
// Cycles reported by CycleInfo. It is sufficient to check the PHIs in |
--- |
| 1708 |
// every Cycle header; if such a node is marked unknown, this will |
--- |
1708 |
// every Cycle header; if such a node is marked unknown, this will |
--- |
| 1709 |
// eventually propagate through the whole net of PHIs in the recurrence. |
--- |
1709 |
// eventually propagate through the whole net of PHIs in the recurrence. |
--- |
| 1710 |
if (mayBeInCycle(CI, cast(Usr), /* HeaderOnly */ true)) { |
0 |
1710 |
if (mayBeInCycle(CI, cast(Usr), /* HeaderOnly */ true)) { |
0 |
| 1711 |
auto BaseOI = It->getSecond(); |
0 |
1711 |
auto BaseOI = It->getSecond(); |
0 |
| 1712 |
BaseOI.addToAll(Offset.getZExtValue()); |
0 |
1712 |
BaseOI.addToAll(Offset.getZExtValue()); |
0 |
| 1713 |
if (IsFirstPHIUser || BaseOI == UsrOI) { |
0 |
1713 |
if (IsFirstPHIUser || BaseOI == UsrOI) { |
0 |
| 1714 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] PHI is invariant " << *CurPtr |
0 |
1714 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] PHI is invariant " << *CurPtr |
0 |
| 1715 |
<< " in " << *Usr << "\n"); |
--- |
1715 |
<< " in " << *Usr << "\n"); |
--- |
| 1716 |
return HandlePassthroughUser(Usr, CurPtr, Follow); |
0 |
1716 |
return HandlePassthroughUser(Usr, CurPtr, Follow); |
0 |
| 1717 |
} |
--- |
1717 |
} |
--- |
| 1718 |
|
--- |
1718 |
|
--- |
| 1719 |
LLVM_DEBUG( |
0 |
1719 |
LLVM_DEBUG( |
0 |
| 1720 |
dbgs() << "[AAPointerInfo] PHI operand pointer offset mismatch " |
--- |
1720 |
dbgs() << "[AAPointerInfo] PHI operand pointer offset mismatch " |
--- |
| 1721 |
<< *CurPtr << " in " << *Usr << "\n"); |
--- |
1721 |
<< *CurPtr << " in " << *Usr << "\n"); |
--- |
| 1722 |
UsrOI.setUnknown(); |
0 |
1722 |
UsrOI.setUnknown(); |
0 |
| 1723 |
Follow = true; |
0 |
1723 |
Follow = true; |
0 |
| 1724 |
return true; |
0 |
1724 |
return true; |
0 |
| 1725 |
} |
0 |
1725 |
} |
0 |
| 1726 |
|
--- |
1726 |
|
--- |
| 1727 |
UsrOI.merge(PtrOI); |
0 |
1727 |
UsrOI.merge(PtrOI); |
0 |
| 1728 |
Follow = true; |
0 |
1728 |
Follow = true; |
0 |
| 1729 |
return true; |
0 |
1729 |
return true; |
0 |
| 1730 |
} |
0 |
1730 |
} |
0 |
| 1731 |
|
--- |
1731 |
|
--- |
| 1732 |
if (auto *LoadI = dyn_cast(Usr)) { |
0 |
1732 |
if (auto *LoadI = dyn_cast(Usr)) { |
0 |
| 1733 |
// If the access is to a pointer that may or may not be the associated |
--- |
1733 |
// If the access is to a pointer that may or may not be the associated |
--- |
| 1734 |
// value, e.g. due to a PHI, we cannot assume it will be read. |
--- |
1734 |
// value, e.g. due to a PHI, we cannot assume it will be read. |
--- |
| 1735 |
AccessKind AK = AccessKind::AK_R; |
0 |
1735 |
AccessKind AK = AccessKind::AK_R; |
0 |
| 1736 |
if (getUnderlyingObject(CurPtr) == &AssociatedValue) |
0 |
1736 |
if (getUnderlyingObject(CurPtr) == &AssociatedValue) |
0 |
| 1737 |
AK = AccessKind(AK | AccessKind::AK_MUST); |
0 |
1737 |
AK = AccessKind(AK | AccessKind::AK_MUST); |
0 |
| 1738 |
else |
--- |
1738 |
else |
--- |
| 1739 |
AK = AccessKind(AK | AccessKind::AK_MAY); |
0 |
1739 |
AK = AccessKind(AK | AccessKind::AK_MAY); |
0 |
| 1740 |
if (!handleAccess(A, *LoadI, /* Content */ nullptr, AK, |
0 |
1740 |
if (!handleAccess(A, *LoadI, /* Content */ nullptr, AK, |
0 |
| 1741 |
OffsetInfoMap[CurPtr].Offsets, Changed, |
0 |
1741 |
OffsetInfoMap[CurPtr].Offsets, Changed, |
0 |
| 1742 |
*LoadI->getType())) |
0 |
1742 |
*LoadI->getType())) |
0 |
| 1743 |
return false; |
0 |
1743 |
return false; |
0 |
| 1744 |
|
--- |
1744 |
|
--- |
| 1745 |
auto IsAssumption = [](Instruction &I) { |
0 |
1745 |
auto IsAssumption = [](Instruction &I) { |
0 |
| 1746 |
if (auto *II = dyn_cast(&I)) |
0 |
1746 |
if (auto *II = dyn_cast(&I)) |
0 |
| 1747 |
return II->isAssumeLikeIntrinsic(); |
0 |
1747 |
return II->isAssumeLikeIntrinsic(); |
0 |
| 1748 |
return false; |
0 |
1748 |
return false; |
0 |
| 1749 |
}; |
--- |
1749 |
}; |
--- |
| 1750 |
|
--- |
1750 |
|
--- |
| 1751 |
auto IsImpactedInRange = [&](Instruction *FromI, Instruction *ToI) { |
0 |
1751 |
auto IsImpactedInRange = [&](Instruction *FromI, Instruction *ToI) { |
0 |
| 1752 |
// Check if the assumption and the load are executed together without |
--- |
1752 |
// Check if the assumption and the load are executed together without |
--- |
| 1753 |
// memory modification. |
--- |
1753 |
// memory modification. |
--- |
| 1754 |
do { |
--- |
1754 |
do { |
--- |
| 1755 |
if (FromI->mayWriteToMemory() && !IsAssumption(*FromI)) |
0 |
1755 |
if (FromI->mayWriteToMemory() && !IsAssumption(*FromI)) |
0 |
| 1756 |
return true; |
0 |
1756 |
return true; |
0 |
| 1757 |
FromI = FromI->getNextNonDebugInstruction(); |
0 |
1757 |
FromI = FromI->getNextNonDebugInstruction(); |
0 |
| 1758 |
} while (FromI && FromI != ToI); |
0 |
1758 |
} while (FromI && FromI != ToI); |
0 |
| 1759 |
return false; |
0 |
1759 |
return false; |
0 |
| 1760 |
}; |
0 |
1760 |
}; |
0 |
| 1761 |
|
--- |
1761 |
|
--- |
| 1762 |
BasicBlock *BB = LoadI->getParent(); |
0 |
1762 |
BasicBlock *BB = LoadI->getParent(); |
0 |
| 1763 |
auto IsValidAssume = [&](IntrinsicInst &IntrI) { |
0 |
1763 |
auto IsValidAssume = [&](IntrinsicInst &IntrI) { |
0 |
| 1764 |
if (IntrI.getIntrinsicID() != Intrinsic::assume) |
0 |
1764 |
if (IntrI.getIntrinsicID() != Intrinsic::assume) |
0 |
| 1765 |
return false; |
0 |
1765 |
return false; |
0 |
| 1766 |
BasicBlock *IntrBB = IntrI.getParent(); |
0 |
1766 |
BasicBlock *IntrBB = IntrI.getParent(); |
0 |
| 1767 |
if (IntrI.getParent() == BB) { |
0 |
1767 |
if (IntrI.getParent() == BB) { |
0 |
| 1768 |
if (IsImpactedInRange(LoadI->getNextNonDebugInstruction(), &IntrI)) |
0 |
1768 |
if (IsImpactedInRange(LoadI->getNextNonDebugInstruction(), &IntrI)) |
0 |
| 1769 |
return false; |
0 |
1769 |
return false; |
0 |
| 1770 |
} else { |
--- |
1770 |
} else { |
--- |
| 1771 |
auto PredIt = pred_begin(IntrBB); |
0 |
1771 |
auto PredIt = pred_begin(IntrBB); |
0 |
| 1772 |
if (PredIt == pred_end(IntrBB)) |
0 |
1772 |
if (PredIt == pred_end(IntrBB)) |
0 |
| 1773 |
return false; |
0 |
1773 |
return false; |
0 |
| 1774 |
if ((*PredIt) != BB) |
0 |
1774 |
if ((*PredIt) != BB) |
0 |
| 1775 |
return false; |
0 |
1775 |
return false; |
0 |
| 1776 |
if (++PredIt != pred_end(IntrBB)) |
0 |
1776 |
if (++PredIt != pred_end(IntrBB)) |
0 |
| 1777 |
return false; |
0 |
1777 |
return false; |
0 |
| 1778 |
for (auto *SuccBB : successors(BB)) { |
0 |
1778 |
for (auto *SuccBB : successors(BB)) { |
0 |
| 1779 |
if (SuccBB == IntrBB) |
0 |
1779 |
if (SuccBB == IntrBB) |
0 |
| 1780 |
continue; |
0 |
1780 |
continue; |
0 |
| 1781 |
if (isa(SuccBB->getTerminator())) |
0 |
1781 |
if (isa(SuccBB->getTerminator())) |
0 |
| 1782 |
continue; |
0 |
1782 |
continue; |
0 |
| 1783 |
return false; |
0 |
1783 |
return false; |
0 |
| 1784 |
} |
--- |
1784 |
} |
--- |
| 1785 |
if (IsImpactedInRange(LoadI->getNextNonDebugInstruction(), |
0 |
1785 |
if (IsImpactedInRange(LoadI->getNextNonDebugInstruction(), |
0 |
| 1786 |
BB->getTerminator())) |
--- |
1786 |
BB->getTerminator())) |
--- |
| 1787 |
return false; |
0 |
1787 |
return false; |
0 |
| 1788 |
if (IsImpactedInRange(&IntrBB->front(), &IntrI)) |
0 |
1788 |
if (IsImpactedInRange(&IntrBB->front(), &IntrI)) |
0 |
| 1789 |
return false; |
0 |
1789 |
return false; |
0 |
| 1790 |
} |
--- |
1790 |
} |
--- |
| 1791 |
return true; |
0 |
1791 |
return true; |
0 |
| 1792 |
}; |
0 |
1792 |
}; |
0 |
| 1793 |
|
--- |
1793 |
|
--- |
| 1794 |
std::pair Assumption; |
0 |
1794 |
std::pair Assumption; |
0 |
| 1795 |
for (const Use &LoadU : LoadI->uses()) { |
0 |
1795 |
for (const Use &LoadU : LoadI->uses()) { |
0 |
| 1796 |
if (auto *CmpI = dyn_cast(LoadU.getUser())) { |
0 |
1796 |
if (auto *CmpI = dyn_cast(LoadU.getUser())) { |
0 |
| 1797 |
if (!CmpI->isEquality() || !CmpI->isTrueWhenEqual()) |
0 |
1797 |
if (!CmpI->isEquality() || !CmpI->isTrueWhenEqual()) |
0 |
| 1798 |
continue; |
0 |
1798 |
continue; |
0 |
| 1799 |
for (const Use &CmpU : CmpI->uses()) { |
0 |
1799 |
for (const Use &CmpU : CmpI->uses()) { |
0 |
| 1800 |
if (auto *IntrI = dyn_cast(CmpU.getUser())) { |
0 |
1800 |
if (auto *IntrI = dyn_cast(CmpU.getUser())) { |
0 |
| 1801 |
if (!IsValidAssume(*IntrI)) |
0 |
1801 |
if (!IsValidAssume(*IntrI)) |
0 |
| 1802 |
continue; |
0 |
1802 |
continue; |
0 |
| 1803 |
int Idx = CmpI->getOperandUse(0) == LoadU; |
0 |
1803 |
int Idx = CmpI->getOperandUse(0) == LoadU; |
0 |
| 1804 |
Assumption = {CmpI->getOperand(Idx), IntrI}; |
0 |
1804 |
Assumption = {CmpI->getOperand(Idx), IntrI}; |
0 |
| 1805 |
break; |
0 |
1805 |
break; |
0 |
| 1806 |
} |
--- |
1806 |
} |
--- |
| 1807 |
} |
--- |
1807 |
} |
--- |
| 1808 |
} |
--- |
1808 |
} |
--- |
| 1809 |
if (Assumption.first) |
0 |
1809 |
if (Assumption.first) |
0 |
| 1810 |
break; |
0 |
1810 |
break; |
0 |
| 1811 |
} |
--- |
1811 |
} |
--- |
| 1812 |
|
--- |
1812 |
|
--- |
| 1813 |
// Check if we found an assumption associated with this load. |
--- |
1813 |
// Check if we found an assumption associated with this load. |
--- |
| 1814 |
if (!Assumption.first || !Assumption.second) |
0 |
1814 |
if (!Assumption.first || !Assumption.second) |
0 |
| 1815 |
return true; |
0 |
1815 |
return true; |
0 |
| 1816 |
|
--- |
1816 |
|
--- |
| 1817 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Assumption found " |
0 |
1817 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Assumption found " |
0 |
| 1818 |
<< *Assumption.second << ": " << *LoadI |
--- |
1818 |
<< *Assumption.second << ": " << *LoadI |
--- |
| 1819 |
<< " == " << *Assumption.first << "\n"); |
--- |
1819 |
<< " == " << *Assumption.first << "\n"); |
--- |
| 1820 |
|
--- |
1820 |
|
--- |
| 1821 |
return handleAccess( |
0 |
1821 |
return handleAccess( |
0 |
| 1822 |
A, *Assumption.second, Assumption.first, AccessKind::AK_ASSUMPTION, |
0 |
1822 |
A, *Assumption.second, Assumption.first, AccessKind::AK_ASSUMPTION, |
0 |
| 1823 |
OffsetInfoMap[CurPtr].Offsets, Changed, *LoadI->getType()); |
0 |
1823 |
OffsetInfoMap[CurPtr].Offsets, Changed, *LoadI->getType()); |
0 |
| 1824 |
} |
--- |
1824 |
} |
--- |
| 1825 |
|
--- |
1825 |
|
--- |
| 1826 |
auto HandleStoreLike = [&](Instruction &I, Value *ValueOp, Type &ValueTy, |
0 |
1826 |
auto HandleStoreLike = [&](Instruction &I, Value *ValueOp, Type &ValueTy, |
0 |
| 1827 |
ArrayRef OtherOps, AccessKind AK) { |
--- |
1827 |
ArrayRef OtherOps, AccessKind AK) { |
--- |
| 1828 |
for (auto *OtherOp : OtherOps) { |
0 |
1828 |
for (auto *OtherOp : OtherOps) { |
0 |
| 1829 |
if (OtherOp == CurPtr) { |
0 |
1829 |
if (OtherOp == CurPtr) { |
0 |
| 1830 |
LLVM_DEBUG( |
0 |
1830 |
LLVM_DEBUG( |
0 |
| 1831 |
dbgs() |
--- |
1831 |
dbgs() |
--- |
| 1832 |
<< "[AAPointerInfo] Escaping use in store like instruction " << I |
--- |
1832 |
<< "[AAPointerInfo] Escaping use in store like instruction " << I |
--- |
| 1833 |
<< "\n"); |
--- |
1833 |
<< "\n"); |
--- |
| 1834 |
return false; |
0 |
1834 |
return false; |
0 |
| 1835 |
} |
--- |
1835 |
} |
--- |
| 1836 |
} |
--- |
1836 |
} |
--- |
| 1837 |
|
--- |
1837 |
|
--- |
| 1838 |
// If the access is to a pointer that may or may not be the associated |
--- |
1838 |
// If the access is to a pointer that may or may not be the associated |
--- |
| 1839 |
// value, e.g. due to a PHI, we cannot assume it will be written. |
--- |
1839 |
// value, e.g. due to a PHI, we cannot assume it will be written. |
--- |
| 1840 |
if (getUnderlyingObject(CurPtr) == &AssociatedValue) |
0 |
1840 |
if (getUnderlyingObject(CurPtr) == &AssociatedValue) |
0 |
| 1841 |
AK = AccessKind(AK | AccessKind::AK_MUST); |
0 |
1841 |
AK = AccessKind(AK | AccessKind::AK_MUST); |
0 |
| 1842 |
else |
--- |
1842 |
else |
--- |
| 1843 |
AK = AccessKind(AK | AccessKind::AK_MAY); |
0 |
1843 |
AK = AccessKind(AK | AccessKind::AK_MAY); |
0 |
| 1844 |
bool UsedAssumedInformation = false; |
0 |
1844 |
bool UsedAssumedInformation = false; |
0 |
| 1845 |
std::optional Content = nullptr; |
0 |
1845 |
std::optional Content = nullptr; |
0 |
| 1846 |
if (ValueOp) |
0 |
1846 |
if (ValueOp) |
0 |
| 1847 |
Content = A.getAssumedSimplified( |
0 |
1847 |
Content = A.getAssumedSimplified( |
0 |
| 1848 |
*ValueOp, *this, UsedAssumedInformation, AA::Interprocedural); |
0 |
1848 |
*ValueOp, *this, UsedAssumedInformation, AA::Interprocedural); |
0 |
| 1849 |
return handleAccess(A, I, Content, AK, OffsetInfoMap[CurPtr].Offsets, |
0 |
1849 |
return handleAccess(A, I, Content, AK, OffsetInfoMap[CurPtr].Offsets, |
0 |
| 1850 |
Changed, ValueTy); |
0 |
1850 |
Changed, ValueTy); |
0 |
| 1851 |
}; |
0 |
1851 |
}; |
0 |
| 1852 |
|
--- |
1852 |
|
--- |
| 1853 |
if (auto *StoreI = dyn_cast(Usr)) |
0 |
1853 |
if (auto *StoreI = dyn_cast(Usr)) |
0 |
| 1854 |
return HandleStoreLike(*StoreI, StoreI->getValueOperand(), |
0 |
1854 |
return HandleStoreLike(*StoreI, StoreI->getValueOperand(), |
0 |
| 1855 |
*StoreI->getValueOperand()->getType(), |
0 |
1855 |
*StoreI->getValueOperand()->getType(), |
0 |
| 1856 |
{StoreI->getValueOperand()}, AccessKind::AK_W); |
0 |
1856 |
{StoreI->getValueOperand()}, AccessKind::AK_W); |
0 |
| 1857 |
if (auto *RMWI = dyn_cast(Usr)) |
0 |
1857 |
if (auto *RMWI = dyn_cast(Usr)) |
0 |
| 1858 |
return HandleStoreLike(*RMWI, nullptr, *RMWI->getValOperand()->getType(), |
0 |
1858 |
return HandleStoreLike(*RMWI, nullptr, *RMWI->getValOperand()->getType(), |
0 |
| 1859 |
{RMWI->getValOperand()}, AccessKind::AK_RW); |
0 |
1859 |
{RMWI->getValOperand()}, AccessKind::AK_RW); |
0 |
| 1860 |
if (auto *CXI = dyn_cast(Usr)) |
0 |
1860 |
if (auto *CXI = dyn_cast(Usr)) |
0 |
| 1861 |
return HandleStoreLike( |
0 |
1861 |
return HandleStoreLike( |
0 |
| 1862 |
*CXI, nullptr, *CXI->getNewValOperand()->getType(), |
0 |
1862 |
*CXI, nullptr, *CXI->getNewValOperand()->getType(), |
0 |
| 1863 |
{CXI->getCompareOperand(), CXI->getNewValOperand()}, |
0 |
1863 |
{CXI->getCompareOperand(), CXI->getNewValOperand()}, |
0 |
| 1864 |
AccessKind::AK_RW); |
0 |
1864 |
AccessKind::AK_RW); |
0 |
| 1865 |
|
--- |
1865 |
|
--- |
| 1866 |
if (auto *CB = dyn_cast(Usr)) { |
0 |
1866 |
if (auto *CB = dyn_cast(Usr)) { |
0 |
| 1867 |
if (CB->isLifetimeStartOrEnd()) |
0 |
1867 |
if (CB->isLifetimeStartOrEnd()) |
0 |
| 1868 |
return true; |
0 |
1868 |
return true; |
0 |
| 1869 |
if (getFreedOperand(CB, TLI) == U) |
0 |
1869 |
if (getFreedOperand(CB, TLI) == U) |
0 |
| 1870 |
return true; |
0 |
1870 |
return true; |
0 |
| 1871 |
if (CB->isArgOperand(&U)) { |
0 |
1871 |
if (CB->isArgOperand(&U)) { |
0 |
| 1872 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
1872 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
| 1873 |
const auto *CSArgPI = A.getAAFor( |
0 |
1873 |
const auto *CSArgPI = A.getAAFor( |
0 |
| 1874 |
*this, IRPosition::callsite_argument(*CB, ArgNo), |
0 |
1874 |
*this, IRPosition::callsite_argument(*CB, ArgNo), |
0 |
| 1875 |
DepClassTy::REQUIRED); |
--- |
1875 |
DepClassTy::REQUIRED); |
--- |
| 1876 |
if (!CSArgPI) |
0 |
1876 |
if (!CSArgPI) |
0 |
| 1877 |
return false; |
0 |
1877 |
return false; |
0 |
| 1878 |
Changed = |
0 |
1878 |
Changed = |
0 |
| 1879 |
translateAndAddState(A, *CSArgPI, OffsetInfoMap[CurPtr], *CB) | |
0 |
1879 |
translateAndAddState(A, *CSArgPI, OffsetInfoMap[CurPtr], *CB) | |
0 |
| 1880 |
Changed; |
--- |
1880 |
Changed; |
--- |
| 1881 |
return isValidState(); |
0 |
1881 |
return isValidState(); |
0 |
| 1882 |
} |
--- |
1882 |
} |
--- |
| 1883 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Call user not handled " << *CB |
0 |
1883 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Call user not handled " << *CB |
0 |
| 1884 |
<< "\n"); |
--- |
1884 |
<< "\n"); |
--- |
| 1885 |
// TODO: Allow some call uses |
--- |
1885 |
// TODO: Allow some call uses |
--- |
| 1886 |
return false; |
0 |
1886 |
return false; |
0 |
| 1887 |
} |
--- |
1887 |
} |
--- |
| 1888 |
|
--- |
1888 |
|
--- |
| 1889 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] User not handled " << *Usr << "\n"); |
0 |
1889 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] User not handled " << *Usr << "\n"); |
0 |
| 1890 |
return false; |
0 |
1890 |
return false; |
0 |
| 1891 |
}; |
0 |
1891 |
}; |
0 |
| 1892 |
auto EquivalentUseCB = [&](const Use &OldU, const Use &NewU) { |
0 |
1892 |
auto EquivalentUseCB = [&](const Use &OldU, const Use &NewU) { |
0 |
| 1893 |
assert(OffsetInfoMap.count(OldU) && "Old use should be known already!"); |
0 |
1893 |
assert(OffsetInfoMap.count(OldU) && "Old use should be known already!"); |
0 |
| 1894 |
if (OffsetInfoMap.count(NewU)) { |
0 |
1894 |
if (OffsetInfoMap.count(NewU)) { |
0 |
| 1895 |
LLVM_DEBUG({ |
0 |
1895 |
LLVM_DEBUG({ |
0 |
| 1896 |
if (!(OffsetInfoMap[NewU] == OffsetInfoMap[OldU])) { |
--- |
1896 |
if (!(OffsetInfoMap[NewU] == OffsetInfoMap[OldU])) { |
--- |
| 1897 |
dbgs() << "[AAPointerInfo] Equivalent use callback failed: " |
--- |
1897 |
dbgs() << "[AAPointerInfo] Equivalent use callback failed: " |
--- |
| 1898 |
<< OffsetInfoMap[NewU] << " vs " << OffsetInfoMap[OldU] |
--- |
1898 |
<< OffsetInfoMap[NewU] << " vs " << OffsetInfoMap[OldU] |
--- |
| 1899 |
<< "\n"; |
--- |
1899 |
<< "\n"; |
--- |
| 1900 |
} |
--- |
1900 |
} |
--- |
| 1901 |
}); |
--- |
1901 |
}); |
--- |
| 1902 |
return OffsetInfoMap[NewU] == OffsetInfoMap[OldU]; |
0 |
1902 |
return OffsetInfoMap[NewU] == OffsetInfoMap[OldU]; |
0 |
| 1903 |
} |
--- |
1903 |
} |
--- |
| 1904 |
OffsetInfoMap[NewU] = OffsetInfoMap[OldU]; |
0 |
1904 |
OffsetInfoMap[NewU] = OffsetInfoMap[OldU]; |
0 |
| 1905 |
return true; |
0 |
1905 |
return true; |
0 |
| 1906 |
}; |
0 |
1906 |
}; |
0 |
| 1907 |
if (!A.checkForAllUses(UsePred, *this, AssociatedValue, |
0 |
1907 |
if (!A.checkForAllUses(UsePred, *this, AssociatedValue, |
0 |
| 1908 |
/* CheckBBLivenessOnly */ true, DepClassTy::OPTIONAL, |
--- |
1908 |
/* CheckBBLivenessOnly */ true, DepClassTy::OPTIONAL, |
--- |
| 1909 |
/* IgnoreDroppableUses */ true, EquivalentUseCB)) { |
--- |
1909 |
/* IgnoreDroppableUses */ true, EquivalentUseCB)) { |
--- |
| 1910 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Check for all uses failed, abort!\n"); |
0 |
1910 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Check for all uses failed, abort!\n"); |
0 |
| 1911 |
return indicatePessimisticFixpoint(); |
0 |
1911 |
return indicatePessimisticFixpoint(); |
0 |
| 1912 |
} |
--- |
1912 |
} |
--- |
| 1913 |
|
--- |
1913 |
|
--- |
| 1914 |
LLVM_DEBUG({ |
0 |
1914 |
LLVM_DEBUG({ |
0 |
| 1915 |
dbgs() << "Accesses by bin after update:\n"; |
--- |
1915 |
dbgs() << "Accesses by bin after update:\n"; |
--- |
| 1916 |
dumpState(dbgs()); |
--- |
1916 |
dumpState(dbgs()); |
--- |
| 1917 |
}); |
--- |
1917 |
}); |
--- |
| 1918 |
|
--- |
1918 |
|
--- |
| 1919 |
return Changed; |
0 |
1919 |
return Changed; |
0 |
| 1920 |
} |
0 |
1920 |
} |
0 |
| 1921 |
|
--- |
1921 |
|
--- |
| 1922 |
struct AAPointerInfoReturned final : AAPointerInfoImpl { |
--- |
1922 |
struct AAPointerInfoReturned final : AAPointerInfoImpl { |
--- |
| 1923 |
AAPointerInfoReturned(const IRPosition &IRP, Attributor &A) |
0 |
1923 |
AAPointerInfoReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 1924 |
: AAPointerInfoImpl(IRP, A) {} |
0 |
1924 |
: AAPointerInfoImpl(IRP, A) {} |
0 |
| 1925 |
|
--- |
1925 |
|
--- |
| 1926 |
/// See AbstractAttribute::updateImpl(...). |
--- |
1926 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 1927 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
1927 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 1928 |
return indicatePessimisticFixpoint(); |
0 |
1928 |
return indicatePessimisticFixpoint(); |
0 |
| 1929 |
} |
--- |
1929 |
} |
--- |
| 1930 |
|
--- |
1930 |
|
--- |
| 1931 |
/// See AbstractAttribute::trackStatistics() |
--- |
1931 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 1932 |
void trackStatistics() const override { |
0 |
1932 |
void trackStatistics() const override { |
0 |
| 1933 |
AAPointerInfoImpl::trackPointerInfoStatistics(getIRPosition()); |
0 |
1933 |
AAPointerInfoImpl::trackPointerInfoStatistics(getIRPosition()); |
0 |
| 1934 |
} |
0 |
1934 |
} |
0 |
| 1935 |
}; |
--- |
1935 |
}; |
--- |
| 1936 |
|
--- |
1936 |
|
--- |
| 1937 |
struct AAPointerInfoArgument final : AAPointerInfoFloating { |
--- |
1937 |
struct AAPointerInfoArgument final : AAPointerInfoFloating { |
--- |
| 1938 |
AAPointerInfoArgument(const IRPosition &IRP, Attributor &A) |
0 |
1938 |
AAPointerInfoArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 1939 |
: AAPointerInfoFloating(IRP, A) {} |
0 |
1939 |
: AAPointerInfoFloating(IRP, A) {} |
0 |
| 1940 |
|
--- |
1940 |
|
--- |
| 1941 |
/// See AbstractAttribute::trackStatistics() |
--- |
1941 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 1942 |
void trackStatistics() const override { |
0 |
1942 |
void trackStatistics() const override { |
0 |
| 1943 |
AAPointerInfoImpl::trackPointerInfoStatistics(getIRPosition()); |
0 |
1943 |
AAPointerInfoImpl::trackPointerInfoStatistics(getIRPosition()); |
0 |
| 1944 |
} |
0 |
1944 |
} |
0 |
| 1945 |
}; |
--- |
1945 |
}; |
--- |
| 1946 |
|
--- |
1946 |
|
--- |
| 1947 |
struct AAPointerInfoCallSiteArgument final : AAPointerInfoFloating { |
--- |
1947 |
struct AAPointerInfoCallSiteArgument final : AAPointerInfoFloating { |
--- |
| 1948 |
AAPointerInfoCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
1948 |
AAPointerInfoCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 1949 |
: AAPointerInfoFloating(IRP, A) {} |
0 |
1949 |
: AAPointerInfoFloating(IRP, A) {} |
0 |
| 1950 |
|
--- |
1950 |
|
--- |
| 1951 |
/// See AbstractAttribute::updateImpl(...). |
--- |
1951 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 1952 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
1952 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 1953 |
using namespace AA::PointerInfo; |
--- |
1953 |
using namespace AA::PointerInfo; |
--- |
| 1954 |
// We handle memory intrinsics explicitly, at least the first (= |
--- |
1954 |
// We handle memory intrinsics explicitly, at least the first (= |
--- |
| 1955 |
// destination) and second (=source) arguments as we know how they are |
--- |
1955 |
// destination) and second (=source) arguments as we know how they are |
--- |
| 1956 |
// accessed. |
--- |
1956 |
// accessed. |
--- |
| 1957 |
if (auto *MI = dyn_cast_or_null(getCtxI())) { |
0 |
1957 |
if (auto *MI = dyn_cast_or_null(getCtxI())) { |
0 |
| 1958 |
ConstantInt *Length = dyn_cast(MI->getLength()); |
0 |
1958 |
ConstantInt *Length = dyn_cast(MI->getLength()); |
0 |
| 1959 |
int64_t LengthVal = AA::RangeTy::Unknown; |
0 |
1959 |
int64_t LengthVal = AA::RangeTy::Unknown; |
0 |
| 1960 |
if (Length) |
0 |
1960 |
if (Length) |
0 |
| 1961 |
LengthVal = Length->getSExtValue(); |
0 |
1961 |
LengthVal = Length->getSExtValue(); |
0 |
| 1962 |
unsigned ArgNo = getIRPosition().getCallSiteArgNo(); |
0 |
1962 |
unsigned ArgNo = getIRPosition().getCallSiteArgNo(); |
0 |
| 1963 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
1963 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 1964 |
if (ArgNo > 1) { |
0 |
1964 |
if (ArgNo > 1) { |
0 |
| 1965 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Unhandled memory intrinsic " |
0 |
1965 |
LLVM_DEBUG(dbgs() << "[AAPointerInfo] Unhandled memory intrinsic " |
0 |
| 1966 |
<< *MI << "\n"); |
--- |
1966 |
<< *MI << "\n"); |
--- |
| 1967 |
return indicatePessimisticFixpoint(); |
0 |
1967 |
return indicatePessimisticFixpoint(); |
0 |
| 1968 |
} else { |
--- |
1968 |
} else { |
--- |
| 1969 |
auto Kind = |
0 |
1969 |
auto Kind = |
0 |
| 1970 |
ArgNo == 0 ? AccessKind::AK_MUST_WRITE : AccessKind::AK_MUST_READ; |
0 |
1970 |
ArgNo == 0 ? AccessKind::AK_MUST_WRITE : AccessKind::AK_MUST_READ; |
0 |
| 1971 |
Changed = |
--- |
1971 |
Changed = |
--- |
| 1972 |
Changed | addAccess(A, {0, LengthVal}, *MI, nullptr, Kind, nullptr); |
0 |
1972 |
Changed | addAccess(A, {0, LengthVal}, *MI, nullptr, Kind, nullptr); |
0 |
| 1973 |
} |
--- |
1973 |
} |
--- |
| 1974 |
LLVM_DEBUG({ |
0 |
1974 |
LLVM_DEBUG({ |
0 |
| 1975 |
dbgs() << "Accesses by bin after update:\n"; |
--- |
1975 |
dbgs() << "Accesses by bin after update:\n"; |
--- |
| 1976 |
dumpState(dbgs()); |
--- |
1976 |
dumpState(dbgs()); |
--- |
| 1977 |
}); |
--- |
1977 |
}); |
--- |
| 1978 |
|
--- |
1978 |
|
--- |
| 1979 |
return Changed; |
0 |
1979 |
return Changed; |
0 |
| 1980 |
} |
--- |
1980 |
} |
--- |
| 1981 |
|
--- |
1981 |
|
--- |
| 1982 |
// TODO: Once we have call site specific value information we can provide |
--- |
1982 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 1983 |
// call site specific liveness information and then it makes |
--- |
1983 |
// call site specific liveness information and then it makes |
--- |
| 1984 |
// sense to specialize attributes for call sites arguments instead of |
--- |
1984 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 1985 |
// redirecting requests to the callee argument. |
--- |
1985 |
// redirecting requests to the callee argument. |
--- |
| 1986 |
Argument *Arg = getAssociatedArgument(); |
0 |
1986 |
Argument *Arg = getAssociatedArgument(); |
0 |
| 1987 |
if (Arg) { |
0 |
1987 |
if (Arg) { |
0 |
| 1988 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
1988 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
| 1989 |
auto *ArgAA = |
--- |
1989 |
auto *ArgAA = |
--- |
| 1990 |
A.getAAFor(*this, ArgPos, DepClassTy::REQUIRED); |
0 |
1990 |
A.getAAFor(*this, ArgPos, DepClassTy::REQUIRED); |
0 |
| 1991 |
if (ArgAA && ArgAA->getState().isValidState()) |
0 |
1991 |
if (ArgAA && ArgAA->getState().isValidState()) |
0 |
| 1992 |
return translateAndAddStateFromCallee(A, *ArgAA, |
0 |
1992 |
return translateAndAddStateFromCallee(A, *ArgAA, |
0 |
| 1993 |
*cast(getCtxI())); |
0 |
1993 |
*cast(getCtxI())); |
0 |
| 1994 |
if (!Arg->getParent()->isDeclaration()) |
0 |
1994 |
if (!Arg->getParent()->isDeclaration()) |
0 |
| 1995 |
return indicatePessimisticFixpoint(); |
0 |
1995 |
return indicatePessimisticFixpoint(); |
0 |
| 1996 |
} |
--- |
1996 |
} |
--- |
| 1997 |
|
--- |
1997 |
|
--- |
| 1998 |
bool IsKnownNoCapture; |
--- |
1998 |
bool IsKnownNoCapture; |
--- |
| 1999 |
if (!AA::hasAssumedIRAttr( |
0 |
1999 |
if (!AA::hasAssumedIRAttr( |
0 |
| 2000 |
A, this, getIRPosition(), DepClassTy::OPTIONAL, IsKnownNoCapture)) |
0 |
2000 |
A, this, getIRPosition(), DepClassTy::OPTIONAL, IsKnownNoCapture)) |
0 |
| 2001 |
return indicatePessimisticFixpoint(); |
0 |
2001 |
return indicatePessimisticFixpoint(); |
0 |
| 2002 |
|
--- |
2002 |
|
--- |
| 2003 |
bool IsKnown = false; |
0 |
2003 |
bool IsKnown = false; |
0 |
| 2004 |
if (AA::isAssumedReadNone(A, getIRPosition(), *this, IsKnown)) |
0 |
2004 |
if (AA::isAssumedReadNone(A, getIRPosition(), *this, IsKnown)) |
0 |
| 2005 |
return ChangeStatus::UNCHANGED; |
0 |
2005 |
return ChangeStatus::UNCHANGED; |
0 |
| 2006 |
bool ReadOnly = AA::isAssumedReadOnly(A, getIRPosition(), *this, IsKnown); |
0 |
2006 |
bool ReadOnly = AA::isAssumedReadOnly(A, getIRPosition(), *this, IsKnown); |
0 |
| 2007 |
auto Kind = |
0 |
2007 |
auto Kind = |
0 |
| 2008 |
ReadOnly ? AccessKind::AK_MAY_READ : AccessKind::AK_MAY_READ_WRITE; |
0 |
2008 |
ReadOnly ? AccessKind::AK_MAY_READ : AccessKind::AK_MAY_READ_WRITE; |
0 |
| 2009 |
return addAccess(A, AA::RangeTy::getUnknown(), *getCtxI(), nullptr, Kind, |
0 |
2009 |
return addAccess(A, AA::RangeTy::getUnknown(), *getCtxI(), nullptr, Kind, |
0 |
| 2010 |
nullptr); |
0 |
2010 |
nullptr); |
0 |
| 2011 |
} |
--- |
2011 |
} |
--- |
| 2012 |
|
--- |
2012 |
|
--- |
| 2013 |
/// See AbstractAttribute::trackStatistics() |
--- |
2013 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2014 |
void trackStatistics() const override { |
0 |
2014 |
void trackStatistics() const override { |
0 |
| 2015 |
AAPointerInfoImpl::trackPointerInfoStatistics(getIRPosition()); |
0 |
2015 |
AAPointerInfoImpl::trackPointerInfoStatistics(getIRPosition()); |
0 |
| 2016 |
} |
0 |
2016 |
} |
0 |
| 2017 |
}; |
--- |
2017 |
}; |
--- |
| 2018 |
|
--- |
2018 |
|
--- |
| 2019 |
struct AAPointerInfoCallSiteReturned final : AAPointerInfoFloating { |
--- |
2019 |
struct AAPointerInfoCallSiteReturned final : AAPointerInfoFloating { |
--- |
| 2020 |
AAPointerInfoCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
2020 |
AAPointerInfoCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 2021 |
: AAPointerInfoFloating(IRP, A) {} |
0 |
2021 |
: AAPointerInfoFloating(IRP, A) {} |
0 |
| 2022 |
|
--- |
2022 |
|
--- |
| 2023 |
/// See AbstractAttribute::trackStatistics() |
--- |
2023 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2024 |
void trackStatistics() const override { |
0 |
2024 |
void trackStatistics() const override { |
0 |
| 2025 |
AAPointerInfoImpl::trackPointerInfoStatistics(getIRPosition()); |
0 |
2025 |
AAPointerInfoImpl::trackPointerInfoStatistics(getIRPosition()); |
0 |
| 2026 |
} |
0 |
2026 |
} |
0 |
| 2027 |
}; |
--- |
2027 |
}; |
--- |
| 2028 |
} // namespace |
--- |
2028 |
} // namespace |
--- |
| 2029 |
|
--- |
2029 |
|
--- |
| 2030 |
/// -----------------------NoUnwind Function Attribute-------------------------- |
--- |
2030 |
/// -----------------------NoUnwind Function Attribute-------------------------- |
--- |
| 2031 |
|
--- |
2031 |
|
--- |
| 2032 |
namespace { |
--- |
2032 |
namespace { |
--- |
| 2033 |
struct AANoUnwindImpl : AANoUnwind { |
--- |
2033 |
struct AANoUnwindImpl : AANoUnwind { |
--- |
| 2034 |
AANoUnwindImpl(const IRPosition &IRP, Attributor &A) : AANoUnwind(IRP, A) {} |
0 |
2034 |
AANoUnwindImpl(const IRPosition &IRP, Attributor &A) : AANoUnwind(IRP, A) {} |
0 |
| 2035 |
|
--- |
2035 |
|
--- |
| 2036 |
/// See AbstractAttribute::initialize(...). |
--- |
2036 |
/// See AbstractAttribute::initialize(...). |
--- |
| 2037 |
void initialize(Attributor &A) override { |
0 |
2037 |
void initialize(Attributor &A) override { |
0 |
| 2038 |
bool IsKnown; |
--- |
2038 |
bool IsKnown; |
--- |
| 2039 |
assert(!AA::hasAssumedIRAttr( |
0 |
2039 |
assert(!AA::hasAssumedIRAttr( |
0 |
| 2040 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
2040 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
| 2041 |
(void)IsKnown; |
--- |
2041 |
(void)IsKnown; |
--- |
| 2042 |
} |
0 |
2042 |
} |
0 |
| 2043 |
|
--- |
2043 |
|
--- |
| 2044 |
const std::string getAsStr(Attributor *A) const override { |
0 |
2044 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 2045 |
return getAssumed() ? "nounwind" : "may-unwind"; |
0 |
2045 |
return getAssumed() ? "nounwind" : "may-unwind"; |
0 |
| 2046 |
} |
--- |
2046 |
} |
--- |
| 2047 |
|
--- |
2047 |
|
--- |
| 2048 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2048 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2049 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2049 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2050 |
auto Opcodes = { |
0 |
2050 |
auto Opcodes = { |
0 |
| 2051 |
(unsigned)Instruction::Invoke, (unsigned)Instruction::CallBr, |
--- |
2051 |
(unsigned)Instruction::Invoke, (unsigned)Instruction::CallBr, |
--- |
| 2052 |
(unsigned)Instruction::Call, (unsigned)Instruction::CleanupRet, |
--- |
2052 |
(unsigned)Instruction::Call, (unsigned)Instruction::CleanupRet, |
--- |
| 2053 |
(unsigned)Instruction::CatchSwitch, (unsigned)Instruction::Resume}; |
0 |
2053 |
(unsigned)Instruction::CatchSwitch, (unsigned)Instruction::Resume}; |
0 |
| 2054 |
|
--- |
2054 |
|
--- |
| 2055 |
auto CheckForNoUnwind = [&](Instruction &I) { |
0 |
2055 |
auto CheckForNoUnwind = [&](Instruction &I) { |
0 |
| 2056 |
if (!I.mayThrow(/* IncludePhaseOneUnwind */ true)) |
0 |
2056 |
if (!I.mayThrow(/* IncludePhaseOneUnwind */ true)) |
0 |
| 2057 |
return true; |
0 |
2057 |
return true; |
0 |
| 2058 |
|
--- |
2058 |
|
--- |
| 2059 |
if (const auto *CB = dyn_cast(&I)) { |
0 |
2059 |
if (const auto *CB = dyn_cast(&I)) { |
0 |
| 2060 |
bool IsKnownNoUnwind; |
--- |
2060 |
bool IsKnownNoUnwind; |
--- |
| 2061 |
return AA::hasAssumedIRAttr( |
0 |
2061 |
return AA::hasAssumedIRAttr( |
0 |
| 2062 |
A, this, IRPosition::callsite_function(*CB), DepClassTy::REQUIRED, |
0 |
2062 |
A, this, IRPosition::callsite_function(*CB), DepClassTy::REQUIRED, |
0 |
| 2063 |
IsKnownNoUnwind); |
0 |
2063 |
IsKnownNoUnwind); |
0 |
| 2064 |
} |
--- |
2064 |
} |
--- |
| 2065 |
return false; |
0 |
2065 |
return false; |
0 |
| 2066 |
}; |
0 |
2066 |
}; |
0 |
| 2067 |
|
--- |
2067 |
|
--- |
| 2068 |
bool UsedAssumedInformation = false; |
0 |
2068 |
bool UsedAssumedInformation = false; |
0 |
| 2069 |
if (!A.checkForAllInstructions(CheckForNoUnwind, *this, Opcodes, |
0 |
2069 |
if (!A.checkForAllInstructions(CheckForNoUnwind, *this, Opcodes, |
0 |
| 2070 |
UsedAssumedInformation)) |
--- |
2070 |
UsedAssumedInformation)) |
--- |
| 2071 |
return indicatePessimisticFixpoint(); |
0 |
2071 |
return indicatePessimisticFixpoint(); |
0 |
| 2072 |
|
--- |
2072 |
|
--- |
| 2073 |
return ChangeStatus::UNCHANGED; |
0 |
2073 |
return ChangeStatus::UNCHANGED; |
0 |
| 2074 |
} |
--- |
2074 |
} |
--- |
| 2075 |
}; |
--- |
2075 |
}; |
--- |
| 2076 |
|
--- |
2076 |
|
--- |
| 2077 |
struct AANoUnwindFunction final : public AANoUnwindImpl { |
--- |
2077 |
struct AANoUnwindFunction final : public AANoUnwindImpl { |
--- |
| 2078 |
AANoUnwindFunction(const IRPosition &IRP, Attributor &A) |
0 |
2078 |
AANoUnwindFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 2079 |
: AANoUnwindImpl(IRP, A) {} |
0 |
2079 |
: AANoUnwindImpl(IRP, A) {} |
0 |
| 2080 |
|
--- |
2080 |
|
--- |
| 2081 |
/// See AbstractAttribute::trackStatistics() |
--- |
2081 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2082 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(nounwind) } |
0 |
2082 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(nounwind) } |
0 |
| 2083 |
}; |
--- |
2083 |
}; |
--- |
| 2084 |
|
--- |
2084 |
|
--- |
| 2085 |
/// NoUnwind attribute deduction for a call sites. |
--- |
2085 |
/// NoUnwind attribute deduction for a call sites. |
--- |
| 2086 |
struct AANoUnwindCallSite final : AANoUnwindImpl { |
--- |
2086 |
struct AANoUnwindCallSite final : AANoUnwindImpl { |
--- |
| 2087 |
AANoUnwindCallSite(const IRPosition &IRP, Attributor &A) |
0 |
2087 |
AANoUnwindCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 2088 |
: AANoUnwindImpl(IRP, A) {} |
0 |
2088 |
: AANoUnwindImpl(IRP, A) {} |
0 |
| 2089 |
|
--- |
2089 |
|
--- |
| 2090 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2090 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2091 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2091 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2092 |
// TODO: Once we have call site specific value information we can provide |
--- |
2092 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 2093 |
// call site specific liveness information and then it makes |
--- |
2093 |
// call site specific liveness information and then it makes |
--- |
| 2094 |
// sense to specialize attributes for call sites arguments instead of |
--- |
2094 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 2095 |
// redirecting requests to the callee argument. |
--- |
2095 |
// redirecting requests to the callee argument. |
--- |
| 2096 |
Function *F = getAssociatedFunction(); |
0 |
2096 |
Function *F = getAssociatedFunction(); |
0 |
| 2097 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
2097 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
| 2098 |
bool IsKnownNoUnwind; |
--- |
2098 |
bool IsKnownNoUnwind; |
--- |
| 2099 |
if (AA::hasAssumedIRAttr( |
0 |
2099 |
if (AA::hasAssumedIRAttr( |
0 |
| 2100 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownNoUnwind)) |
--- |
2100 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownNoUnwind)) |
--- |
| 2101 |
return ChangeStatus::UNCHANGED; |
0 |
2101 |
return ChangeStatus::UNCHANGED; |
0 |
| 2102 |
return indicatePessimisticFixpoint(); |
0 |
2102 |
return indicatePessimisticFixpoint(); |
0 |
| 2103 |
} |
--- |
2103 |
} |
--- |
| 2104 |
|
--- |
2104 |
|
--- |
| 2105 |
/// See AbstractAttribute::trackStatistics() |
--- |
2105 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2106 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(nounwind); } |
0 |
2106 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(nounwind); } |
0 |
| 2107 |
}; |
--- |
2107 |
}; |
--- |
| 2108 |
} // namespace |
--- |
2108 |
} // namespace |
--- |
| 2109 |
|
--- |
2109 |
|
--- |
| 2110 |
/// ------------------------ NoSync Function Attribute ------------------------- |
--- |
2110 |
/// ------------------------ NoSync Function Attribute ------------------------- |
--- |
| 2111 |
|
--- |
2111 |
|
--- |
| 2112 |
bool AANoSync::isAlignedBarrier(const CallBase &CB, bool ExecutedAligned) { |
0 |
2112 |
bool AANoSync::isAlignedBarrier(const CallBase &CB, bool ExecutedAligned) { |
0 |
| 2113 |
switch (CB.getIntrinsicID()) { |
0 |
2113 |
switch (CB.getIntrinsicID()) { |
0 |
| 2114 |
case Intrinsic::nvvm_barrier0: |
0 |
2114 |
case Intrinsic::nvvm_barrier0: |
0 |
| 2115 |
case Intrinsic::nvvm_barrier0_and: |
--- |
2115 |
case Intrinsic::nvvm_barrier0_and: |
--- |
| 2116 |
case Intrinsic::nvvm_barrier0_or: |
--- |
2116 |
case Intrinsic::nvvm_barrier0_or: |
--- |
| 2117 |
case Intrinsic::nvvm_barrier0_popc: |
--- |
2117 |
case Intrinsic::nvvm_barrier0_popc: |
--- |
| 2118 |
return true; |
0 |
2118 |
return true; |
0 |
| 2119 |
case Intrinsic::amdgcn_s_barrier: |
0 |
2119 |
case Intrinsic::amdgcn_s_barrier: |
0 |
| 2120 |
if (ExecutedAligned) |
0 |
2120 |
if (ExecutedAligned) |
0 |
| 2121 |
return true; |
0 |
2121 |
return true; |
0 |
| 2122 |
break; |
0 |
2122 |
break; |
0 |
| 2123 |
default: |
0 |
2123 |
default: |
0 |
| 2124 |
break; |
0 |
2124 |
break; |
0 |
| 2125 |
} |
--- |
2125 |
} |
--- |
| 2126 |
return hasAssumption(CB, KnownAssumptionString("ompx_aligned_barrier")); |
0 |
2126 |
return hasAssumption(CB, KnownAssumptionString("ompx_aligned_barrier")); |
0 |
| 2127 |
} |
--- |
2127 |
} |
--- |
| 2128 |
|
--- |
2128 |
|
--- |
| 2129 |
bool AANoSync::isNonRelaxedAtomic(const Instruction *I) { |
0 |
2129 |
bool AANoSync::isNonRelaxedAtomic(const Instruction *I) { |
0 |
| 2130 |
if (!I->isAtomic()) |
0 |
2130 |
if (!I->isAtomic()) |
0 |
| 2131 |
return false; |
0 |
2131 |
return false; |
0 |
| 2132 |
|
--- |
2132 |
|
--- |
| 2133 |
if (auto *FI = dyn_cast(I)) |
0 |
2133 |
if (auto *FI = dyn_cast(I)) |
0 |
| 2134 |
// All legal orderings for fence are stronger than monotonic. |
--- |
2134 |
// All legal orderings for fence are stronger than monotonic. |
--- |
| 2135 |
return FI->getSyncScopeID() != SyncScope::SingleThread; |
0 |
2135 |
return FI->getSyncScopeID() != SyncScope::SingleThread; |
0 |
| 2136 |
if (auto *AI = dyn_cast(I)) { |
0 |
2136 |
if (auto *AI = dyn_cast(I)) { |
0 |
| 2137 |
// Unordered is not a legal ordering for cmpxchg. |
--- |
2137 |
// Unordered is not a legal ordering for cmpxchg. |
--- |
| 2138 |
return (AI->getSuccessOrdering() != AtomicOrdering::Monotonic || |
0 |
2138 |
return (AI->getSuccessOrdering() != AtomicOrdering::Monotonic || |
0 |
| 2139 |
AI->getFailureOrdering() != AtomicOrdering::Monotonic); |
0 |
2139 |
AI->getFailureOrdering() != AtomicOrdering::Monotonic); |
0 |
| 2140 |
} |
--- |
2140 |
} |
--- |
| 2141 |
|
--- |
2141 |
|
--- |
| 2142 |
AtomicOrdering Ordering; |
--- |
2142 |
AtomicOrdering Ordering; |
--- |
| 2143 |
switch (I->getOpcode()) { |
0 |
2143 |
switch (I->getOpcode()) { |
0 |
| 2144 |
case Instruction::AtomicRMW: |
0 |
2144 |
case Instruction::AtomicRMW: |
0 |
| 2145 |
Ordering = cast(I)->getOrdering(); |
0 |
2145 |
Ordering = cast(I)->getOrdering(); |
0 |
| 2146 |
break; |
0 |
2146 |
break; |
0 |
| 2147 |
case Instruction::Store: |
0 |
2147 |
case Instruction::Store: |
0 |
| 2148 |
Ordering = cast(I)->getOrdering(); |
0 |
2148 |
Ordering = cast(I)->getOrdering(); |
0 |
| 2149 |
break; |
0 |
2149 |
break; |
0 |
| 2150 |
case Instruction::Load: |
0 |
2150 |
case Instruction::Load: |
0 |
| 2151 |
Ordering = cast(I)->getOrdering(); |
0 |
2151 |
Ordering = cast(I)->getOrdering(); |
0 |
| 2152 |
break; |
0 |
2152 |
break; |
0 |
| 2153 |
default: |
0 |
2153 |
default: |
0 |
| 2154 |
llvm_unreachable( |
0 |
2154 |
llvm_unreachable( |
0 |
| 2155 |
"New atomic operations need to be known in the attributor."); |
--- |
2155 |
"New atomic operations need to be known in the attributor."); |
--- |
| 2156 |
} |
--- |
2156 |
} |
--- |
| 2157 |
|
--- |
2157 |
|
--- |
| 2158 |
return (Ordering != AtomicOrdering::Unordered && |
0 |
2158 |
return (Ordering != AtomicOrdering::Unordered && |
0 |
| 2159 |
Ordering != AtomicOrdering::Monotonic); |
0 |
2159 |
Ordering != AtomicOrdering::Monotonic); |
0 |
| 2160 |
} |
--- |
2160 |
} |
--- |
| 2161 |
|
--- |
2161 |
|
--- |
| 2162 |
/// Return true if this intrinsic is nosync. This is only used for intrinsics |
--- |
2162 |
/// Return true if this intrinsic is nosync. This is only used for intrinsics |
--- |
| 2163 |
/// which would be nosync except that they have a volatile flag. All other |
--- |
2163 |
/// which would be nosync except that they have a volatile flag. All other |
--- |
| 2164 |
/// intrinsics are simply annotated with the nosync attribute in Intrinsics.td. |
--- |
2164 |
/// intrinsics are simply annotated with the nosync attribute in Intrinsics.td. |
--- |
| 2165 |
bool AANoSync::isNoSyncIntrinsic(const Instruction *I) { |
0 |
2165 |
bool AANoSync::isNoSyncIntrinsic(const Instruction *I) { |
0 |
| 2166 |
if (auto *MI = dyn_cast(I)) |
0 |
2166 |
if (auto *MI = dyn_cast(I)) |
0 |
| 2167 |
return !MI->isVolatile(); |
0 |
2167 |
return !MI->isVolatile(); |
0 |
| 2168 |
return false; |
0 |
2168 |
return false; |
0 |
| 2169 |
} |
--- |
2169 |
} |
--- |
| 2170 |
|
--- |
2170 |
|
--- |
| 2171 |
namespace { |
--- |
2171 |
namespace { |
--- |
| 2172 |
struct AANoSyncImpl : AANoSync { |
--- |
2172 |
struct AANoSyncImpl : AANoSync { |
--- |
| 2173 |
AANoSyncImpl(const IRPosition &IRP, Attributor &A) : AANoSync(IRP, A) {} |
0 |
2173 |
AANoSyncImpl(const IRPosition &IRP, Attributor &A) : AANoSync(IRP, A) {} |
0 |
| 2174 |
|
--- |
2174 |
|
--- |
| 2175 |
/// See AbstractAttribute::initialize(...). |
--- |
2175 |
/// See AbstractAttribute::initialize(...). |
--- |
| 2176 |
void initialize(Attributor &A) override { |
0 |
2176 |
void initialize(Attributor &A) override { |
0 |
| 2177 |
bool IsKnown; |
--- |
2177 |
bool IsKnown; |
--- |
| 2178 |
assert(!AA::hasAssumedIRAttr(A, nullptr, getIRPosition(), |
0 |
2178 |
assert(!AA::hasAssumedIRAttr(A, nullptr, getIRPosition(), |
0 |
| 2179 |
DepClassTy::NONE, IsKnown)); |
--- |
2179 |
DepClassTy::NONE, IsKnown)); |
--- |
| 2180 |
(void)IsKnown; |
--- |
2180 |
(void)IsKnown; |
--- |
| 2181 |
} |
0 |
2181 |
} |
0 |
| 2182 |
|
--- |
2182 |
|
--- |
| 2183 |
const std::string getAsStr(Attributor *A) const override { |
0 |
2183 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 2184 |
return getAssumed() ? "nosync" : "may-sync"; |
0 |
2184 |
return getAssumed() ? "nosync" : "may-sync"; |
0 |
| 2185 |
} |
--- |
2185 |
} |
--- |
| 2186 |
|
--- |
2186 |
|
--- |
| 2187 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2187 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2188 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
2188 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
| 2189 |
}; |
--- |
2189 |
}; |
--- |
| 2190 |
|
--- |
2190 |
|
--- |
| 2191 |
ChangeStatus AANoSyncImpl::updateImpl(Attributor &A) { |
0 |
2191 |
ChangeStatus AANoSyncImpl::updateImpl(Attributor &A) { |
0 |
| 2192 |
|
--- |
2192 |
|
--- |
| 2193 |
auto CheckRWInstForNoSync = [&](Instruction &I) { |
0 |
2193 |
auto CheckRWInstForNoSync = [&](Instruction &I) { |
0 |
| 2194 |
return AA::isNoSyncInst(A, I, *this); |
0 |
2194 |
return AA::isNoSyncInst(A, I, *this); |
0 |
| 2195 |
}; |
0 |
2195 |
}; |
0 |
| 2196 |
|
--- |
2196 |
|
--- |
| 2197 |
auto CheckForNoSync = [&](Instruction &I) { |
0 |
2197 |
auto CheckForNoSync = [&](Instruction &I) { |
0 |
| 2198 |
// At this point we handled all read/write effects and they are all |
--- |
2198 |
// At this point we handled all read/write effects and they are all |
--- |
| 2199 |
// nosync, so they can be skipped. |
--- |
2199 |
// nosync, so they can be skipped. |
--- |
| 2200 |
if (I.mayReadOrWriteMemory()) |
0 |
2200 |
if (I.mayReadOrWriteMemory()) |
0 |
| 2201 |
return true; |
0 |
2201 |
return true; |
0 |
| 2202 |
|
--- |
2202 |
|
--- |
| 2203 |
bool IsKnown; |
--- |
2203 |
bool IsKnown; |
--- |
| 2204 |
CallBase &CB = cast(I); |
0 |
2204 |
CallBase &CB = cast(I); |
0 |
| 2205 |
if (AA::hasAssumedIRAttr( |
0 |
2205 |
if (AA::hasAssumedIRAttr( |
0 |
| 2206 |
A, this, IRPosition::callsite_function(CB), DepClassTy::OPTIONAL, |
0 |
2206 |
A, this, IRPosition::callsite_function(CB), DepClassTy::OPTIONAL, |
0 |
| 2207 |
IsKnown)) |
--- |
2207 |
IsKnown)) |
--- |
| 2208 |
return true; |
0 |
2208 |
return true; |
0 |
| 2209 |
|
--- |
2209 |
|
--- |
| 2210 |
// non-convergent and readnone imply nosync. |
--- |
2210 |
// non-convergent and readnone imply nosync. |
--- |
| 2211 |
return !CB.isConvergent(); |
0 |
2211 |
return !CB.isConvergent(); |
0 |
| 2212 |
}; |
0 |
2212 |
}; |
0 |
| 2213 |
|
--- |
2213 |
|
--- |
| 2214 |
bool UsedAssumedInformation = false; |
0 |
2214 |
bool UsedAssumedInformation = false; |
0 |
| 2215 |
if (!A.checkForAllReadWriteInstructions(CheckRWInstForNoSync, *this, |
0 |
2215 |
if (!A.checkForAllReadWriteInstructions(CheckRWInstForNoSync, *this, |
0 |
| 2216 |
UsedAssumedInformation) || |
0 |
2216 |
UsedAssumedInformation) || |
0 |
| 2217 |
!A.checkForAllCallLikeInstructions(CheckForNoSync, *this, |
0 |
2217 |
!A.checkForAllCallLikeInstructions(CheckForNoSync, *this, |
0 |
| 2218 |
UsedAssumedInformation)) |
--- |
2218 |
UsedAssumedInformation)) |
--- |
| 2219 |
return indicatePessimisticFixpoint(); |
0 |
2219 |
return indicatePessimisticFixpoint(); |
0 |
| 2220 |
|
--- |
2220 |
|
--- |
| 2221 |
return ChangeStatus::UNCHANGED; |
0 |
2221 |
return ChangeStatus::UNCHANGED; |
0 |
| 2222 |
} |
--- |
2222 |
} |
--- |
| 2223 |
|
--- |
2223 |
|
--- |
| 2224 |
struct AANoSyncFunction final : public AANoSyncImpl { |
--- |
2224 |
struct AANoSyncFunction final : public AANoSyncImpl { |
--- |
| 2225 |
AANoSyncFunction(const IRPosition &IRP, Attributor &A) |
0 |
2225 |
AANoSyncFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 2226 |
: AANoSyncImpl(IRP, A) {} |
0 |
2226 |
: AANoSyncImpl(IRP, A) {} |
0 |
| 2227 |
|
--- |
2227 |
|
--- |
| 2228 |
/// See AbstractAttribute::trackStatistics() |
--- |
2228 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2229 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(nosync) } |
0 |
2229 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(nosync) } |
0 |
| 2230 |
}; |
--- |
2230 |
}; |
--- |
| 2231 |
|
--- |
2231 |
|
--- |
| 2232 |
/// NoSync attribute deduction for a call sites. |
--- |
2232 |
/// NoSync attribute deduction for a call sites. |
--- |
| 2233 |
struct AANoSyncCallSite final : AANoSyncImpl { |
--- |
2233 |
struct AANoSyncCallSite final : AANoSyncImpl { |
--- |
| 2234 |
AANoSyncCallSite(const IRPosition &IRP, Attributor &A) |
0 |
2234 |
AANoSyncCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 2235 |
: AANoSyncImpl(IRP, A) {} |
0 |
2235 |
: AANoSyncImpl(IRP, A) {} |
0 |
| 2236 |
|
--- |
2236 |
|
--- |
| 2237 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2237 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2238 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2238 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2239 |
// TODO: Once we have call site specific value information we can provide |
--- |
2239 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 2240 |
// call site specific liveness information and then it makes |
--- |
2240 |
// call site specific liveness information and then it makes |
--- |
| 2241 |
// sense to specialize attributes for call sites arguments instead of |
--- |
2241 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 2242 |
// redirecting requests to the callee argument. |
--- |
2242 |
// redirecting requests to the callee argument. |
--- |
| 2243 |
Function *F = getAssociatedFunction(); |
0 |
2243 |
Function *F = getAssociatedFunction(); |
0 |
| 2244 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
2244 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
| 2245 |
bool IsKnownNoSycn; |
--- |
2245 |
bool IsKnownNoSycn; |
--- |
| 2246 |
if (AA::hasAssumedIRAttr( |
0 |
2246 |
if (AA::hasAssumedIRAttr( |
0 |
| 2247 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownNoSycn)) |
--- |
2247 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownNoSycn)) |
--- |
| 2248 |
return ChangeStatus::UNCHANGED; |
0 |
2248 |
return ChangeStatus::UNCHANGED; |
0 |
| 2249 |
return indicatePessimisticFixpoint(); |
0 |
2249 |
return indicatePessimisticFixpoint(); |
0 |
| 2250 |
} |
--- |
2250 |
} |
--- |
| 2251 |
|
--- |
2251 |
|
--- |
| 2252 |
/// See AbstractAttribute::trackStatistics() |
--- |
2252 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2253 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(nosync); } |
0 |
2253 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(nosync); } |
0 |
| 2254 |
}; |
--- |
2254 |
}; |
--- |
| 2255 |
} // namespace |
--- |
2255 |
} // namespace |
--- |
| 2256 |
|
--- |
2256 |
|
--- |
| 2257 |
/// ------------------------ No-Free Attributes ---------------------------- |
--- |
2257 |
/// ------------------------ No-Free Attributes ---------------------------- |
--- |
| 2258 |
|
--- |
2258 |
|
--- |
| 2259 |
namespace { |
--- |
2259 |
namespace { |
--- |
| 2260 |
struct AANoFreeImpl : public AANoFree { |
--- |
2260 |
struct AANoFreeImpl : public AANoFree { |
--- |
| 2261 |
AANoFreeImpl(const IRPosition &IRP, Attributor &A) : AANoFree(IRP, A) {} |
0 |
2261 |
AANoFreeImpl(const IRPosition &IRP, Attributor &A) : AANoFree(IRP, A) {} |
0 |
| 2262 |
|
--- |
2262 |
|
--- |
| 2263 |
/// See AbstractAttribute::initialize(...). |
--- |
2263 |
/// See AbstractAttribute::initialize(...). |
--- |
| 2264 |
void initialize(Attributor &A) override { |
0 |
2264 |
void initialize(Attributor &A) override { |
0 |
| 2265 |
bool IsKnown; |
--- |
2265 |
bool IsKnown; |
--- |
| 2266 |
assert(!AA::hasAssumedIRAttr(A, nullptr, getIRPosition(), |
0 |
2266 |
assert(!AA::hasAssumedIRAttr(A, nullptr, getIRPosition(), |
0 |
| 2267 |
DepClassTy::NONE, IsKnown)); |
--- |
2267 |
DepClassTy::NONE, IsKnown)); |
--- |
| 2268 |
(void)IsKnown; |
--- |
2268 |
(void)IsKnown; |
--- |
| 2269 |
} |
0 |
2269 |
} |
0 |
| 2270 |
|
--- |
2270 |
|
--- |
| 2271 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2271 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2272 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2272 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2273 |
auto CheckForNoFree = [&](Instruction &I) { |
0 |
2273 |
auto CheckForNoFree = [&](Instruction &I) { |
0 |
| 2274 |
bool IsKnown; |
--- |
2274 |
bool IsKnown; |
--- |
| 2275 |
return AA::hasAssumedIRAttr( |
0 |
2275 |
return AA::hasAssumedIRAttr( |
0 |
| 2276 |
A, this, IRPosition::callsite_function(cast(I)), |
0 |
2276 |
A, this, IRPosition::callsite_function(cast(I)), |
0 |
| 2277 |
DepClassTy::REQUIRED, IsKnown); |
0 |
2277 |
DepClassTy::REQUIRED, IsKnown); |
0 |
| 2278 |
}; |
0 |
2278 |
}; |
0 |
| 2279 |
|
--- |
2279 |
|
--- |
| 2280 |
bool UsedAssumedInformation = false; |
0 |
2280 |
bool UsedAssumedInformation = false; |
0 |
| 2281 |
if (!A.checkForAllCallLikeInstructions(CheckForNoFree, *this, |
0 |
2281 |
if (!A.checkForAllCallLikeInstructions(CheckForNoFree, *this, |
0 |
| 2282 |
UsedAssumedInformation)) |
--- |
2282 |
UsedAssumedInformation)) |
--- |
| 2283 |
return indicatePessimisticFixpoint(); |
0 |
2283 |
return indicatePessimisticFixpoint(); |
0 |
| 2284 |
return ChangeStatus::UNCHANGED; |
0 |
2284 |
return ChangeStatus::UNCHANGED; |
0 |
| 2285 |
} |
--- |
2285 |
} |
--- |
| 2286 |
|
--- |
2286 |
|
--- |
| 2287 |
/// See AbstractAttribute::getAsStr(). |
--- |
2287 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 2288 |
const std::string getAsStr(Attributor *A) const override { |
0 |
2288 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 2289 |
return getAssumed() ? "nofree" : "may-free"; |
0 |
2289 |
return getAssumed() ? "nofree" : "may-free"; |
0 |
| 2290 |
} |
--- |
2290 |
} |
--- |
| 2291 |
}; |
--- |
2291 |
}; |
--- |
| 2292 |
|
--- |
2292 |
|
--- |
| 2293 |
struct AANoFreeFunction final : public AANoFreeImpl { |
--- |
2293 |
struct AANoFreeFunction final : public AANoFreeImpl { |
--- |
| 2294 |
AANoFreeFunction(const IRPosition &IRP, Attributor &A) |
0 |
2294 |
AANoFreeFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 2295 |
: AANoFreeImpl(IRP, A) {} |
0 |
2295 |
: AANoFreeImpl(IRP, A) {} |
0 |
| 2296 |
|
--- |
2296 |
|
--- |
| 2297 |
/// See AbstractAttribute::trackStatistics() |
--- |
2297 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2298 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(nofree) } |
0 |
2298 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(nofree) } |
0 |
| 2299 |
}; |
--- |
2299 |
}; |
--- |
| 2300 |
|
--- |
2300 |
|
--- |
| 2301 |
/// NoFree attribute deduction for a call sites. |
--- |
2301 |
/// NoFree attribute deduction for a call sites. |
--- |
| 2302 |
struct AANoFreeCallSite final : AANoFreeImpl { |
--- |
2302 |
struct AANoFreeCallSite final : AANoFreeImpl { |
--- |
| 2303 |
AANoFreeCallSite(const IRPosition &IRP, Attributor &A) |
0 |
2303 |
AANoFreeCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 2304 |
: AANoFreeImpl(IRP, A) {} |
0 |
2304 |
: AANoFreeImpl(IRP, A) {} |
0 |
| 2305 |
|
--- |
2305 |
|
--- |
| 2306 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2306 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2307 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2307 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2308 |
// TODO: Once we have call site specific value information we can provide |
--- |
2308 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 2309 |
// call site specific liveness information and then it makes |
--- |
2309 |
// call site specific liveness information and then it makes |
--- |
| 2310 |
// sense to specialize attributes for call sites arguments instead of |
--- |
2310 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 2311 |
// redirecting requests to the callee argument. |
--- |
2311 |
// redirecting requests to the callee argument. |
--- |
| 2312 |
Function *F = getAssociatedFunction(); |
0 |
2312 |
Function *F = getAssociatedFunction(); |
0 |
| 2313 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
2313 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
| 2314 |
bool IsKnown; |
--- |
2314 |
bool IsKnown; |
--- |
| 2315 |
if (AA::hasAssumedIRAttr(A, this, FnPos, |
0 |
2315 |
if (AA::hasAssumedIRAttr(A, this, FnPos, |
0 |
| 2316 |
DepClassTy::REQUIRED, IsKnown)) |
--- |
2316 |
DepClassTy::REQUIRED, IsKnown)) |
--- |
| 2317 |
return ChangeStatus::UNCHANGED; |
0 |
2317 |
return ChangeStatus::UNCHANGED; |
0 |
| 2318 |
return indicatePessimisticFixpoint(); |
0 |
2318 |
return indicatePessimisticFixpoint(); |
0 |
| 2319 |
} |
--- |
2319 |
} |
--- |
| 2320 |
|
--- |
2320 |
|
--- |
| 2321 |
/// See AbstractAttribute::trackStatistics() |
--- |
2321 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2322 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(nofree); } |
0 |
2322 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(nofree); } |
0 |
| 2323 |
}; |
--- |
2323 |
}; |
--- |
| 2324 |
|
--- |
2324 |
|
--- |
| 2325 |
/// NoFree attribute for floating values. |
--- |
2325 |
/// NoFree attribute for floating values. |
--- |
| 2326 |
struct AANoFreeFloating : AANoFreeImpl { |
--- |
2326 |
struct AANoFreeFloating : AANoFreeImpl { |
--- |
| 2327 |
AANoFreeFloating(const IRPosition &IRP, Attributor &A) |
0 |
2327 |
AANoFreeFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 2328 |
: AANoFreeImpl(IRP, A) {} |
0 |
2328 |
: AANoFreeImpl(IRP, A) {} |
0 |
| 2329 |
|
--- |
2329 |
|
--- |
| 2330 |
/// See AbstractAttribute::trackStatistics() |
--- |
2330 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2331 |
void trackStatistics() const override{STATS_DECLTRACK_FLOATING_ATTR(nofree)} |
0 |
2331 |
void trackStatistics() const override{STATS_DECLTRACK_FLOATING_ATTR(nofree)} |
0 |
| 2332 |
|
--- |
2332 |
|
--- |
| 2333 |
/// See Abstract Attribute::updateImpl(...). |
--- |
2333 |
/// See Abstract Attribute::updateImpl(...). |
--- |
| 2334 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2334 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2335 |
const IRPosition &IRP = getIRPosition(); |
0 |
2335 |
const IRPosition &IRP = getIRPosition(); |
0 |
| 2336 |
|
--- |
2336 |
|
--- |
| 2337 |
bool IsKnown; |
--- |
2337 |
bool IsKnown; |
--- |
| 2338 |
if (AA::hasAssumedIRAttr(A, this, |
0 |
2338 |
if (AA::hasAssumedIRAttr(A, this, |
0 |
| 2339 |
IRPosition::function_scope(IRP), |
0 |
2339 |
IRPosition::function_scope(IRP), |
0 |
| 2340 |
DepClassTy::OPTIONAL, IsKnown)) |
--- |
2340 |
DepClassTy::OPTIONAL, IsKnown)) |
--- |
| 2341 |
return ChangeStatus::UNCHANGED; |
0 |
2341 |
return ChangeStatus::UNCHANGED; |
0 |
| 2342 |
|
--- |
2342 |
|
--- |
| 2343 |
Value &AssociatedValue = getIRPosition().getAssociatedValue(); |
0 |
2343 |
Value &AssociatedValue = getIRPosition().getAssociatedValue(); |
0 |
| 2344 |
auto Pred = [&](const Use &U, bool &Follow) -> bool { |
0 |
2344 |
auto Pred = [&](const Use &U, bool &Follow) -> bool { |
0 |
| 2345 |
Instruction *UserI = cast(U.getUser()); |
0 |
2345 |
Instruction *UserI = cast(U.getUser()); |
0 |
| 2346 |
if (auto *CB = dyn_cast(UserI)) { |
0 |
2346 |
if (auto *CB = dyn_cast(UserI)) { |
0 |
| 2347 |
if (CB->isBundleOperand(&U)) |
0 |
2347 |
if (CB->isBundleOperand(&U)) |
0 |
| 2348 |
return false; |
0 |
2348 |
return false; |
0 |
| 2349 |
if (!CB->isArgOperand(&U)) |
0 |
2349 |
if (!CB->isArgOperand(&U)) |
0 |
| 2350 |
return true; |
0 |
2350 |
return true; |
0 |
| 2351 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
2351 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
| 2352 |
|
--- |
2352 |
|
--- |
| 2353 |
bool IsKnown; |
--- |
2353 |
bool IsKnown; |
--- |
| 2354 |
return AA::hasAssumedIRAttr( |
0 |
2354 |
return AA::hasAssumedIRAttr( |
0 |
| 2355 |
A, this, IRPosition::callsite_argument(*CB, ArgNo), |
0 |
2355 |
A, this, IRPosition::callsite_argument(*CB, ArgNo), |
0 |
| 2356 |
DepClassTy::REQUIRED, IsKnown); |
0 |
2356 |
DepClassTy::REQUIRED, IsKnown); |
0 |
| 2357 |
} |
--- |
2357 |
} |
--- |
| 2358 |
|
--- |
2358 |
|
--- |
| 2359 |
if (isa(UserI) || isa(UserI) || |
0 |
2359 |
if (isa(UserI) || isa(UserI) || |
0 |
| 2360 |
isa(UserI) || isa(UserI)) { |
0 |
2360 |
isa(UserI) || isa(UserI)) { |
0 |
| 2361 |
Follow = true; |
0 |
2361 |
Follow = true; |
0 |
| 2362 |
return true; |
0 |
2362 |
return true; |
0 |
| 2363 |
} |
--- |
2363 |
} |
--- |
| 2364 |
if (isa(UserI) || isa(UserI) || |
0 |
2364 |
if (isa(UserI) || isa(UserI) || |
0 |
| 2365 |
isa(UserI)) |
0 |
2365 |
isa(UserI)) |
0 |
| 2366 |
return true; |
0 |
2366 |
return true; |
0 |
| 2367 |
|
--- |
2367 |
|
--- |
| 2368 |
// Unknown user. |
--- |
2368 |
// Unknown user. |
--- |
| 2369 |
return false; |
0 |
2369 |
return false; |
0 |
| 2370 |
}; |
0 |
2370 |
}; |
0 |
| 2371 |
if (!A.checkForAllUses(Pred, *this, AssociatedValue)) |
0 |
2371 |
if (!A.checkForAllUses(Pred, *this, AssociatedValue)) |
0 |
| 2372 |
return indicatePessimisticFixpoint(); |
0 |
2372 |
return indicatePessimisticFixpoint(); |
0 |
| 2373 |
|
--- |
2373 |
|
--- |
| 2374 |
return ChangeStatus::UNCHANGED; |
0 |
2374 |
return ChangeStatus::UNCHANGED; |
0 |
| 2375 |
} |
--- |
2375 |
} |
--- |
| 2376 |
}; |
--- |
2376 |
}; |
--- |
| 2377 |
|
--- |
2377 |
|
--- |
| 2378 |
/// NoFree attribute for a call site argument. |
--- |
2378 |
/// NoFree attribute for a call site argument. |
--- |
| 2379 |
struct AANoFreeArgument final : AANoFreeFloating { |
--- |
2379 |
struct AANoFreeArgument final : AANoFreeFloating { |
--- |
| 2380 |
AANoFreeArgument(const IRPosition &IRP, Attributor &A) |
0 |
2380 |
AANoFreeArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 2381 |
: AANoFreeFloating(IRP, A) {} |
0 |
2381 |
: AANoFreeFloating(IRP, A) {} |
0 |
| 2382 |
|
--- |
2382 |
|
--- |
| 2383 |
/// See AbstractAttribute::trackStatistics() |
--- |
2383 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2384 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(nofree) } |
0 |
2384 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(nofree) } |
0 |
| 2385 |
}; |
--- |
2385 |
}; |
--- |
| 2386 |
|
--- |
2386 |
|
--- |
| 2387 |
/// NoFree attribute for call site arguments. |
--- |
2387 |
/// NoFree attribute for call site arguments. |
--- |
| 2388 |
struct AANoFreeCallSiteArgument final : AANoFreeFloating { |
--- |
2388 |
struct AANoFreeCallSiteArgument final : AANoFreeFloating { |
--- |
| 2389 |
AANoFreeCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
2389 |
AANoFreeCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 2390 |
: AANoFreeFloating(IRP, A) {} |
0 |
2390 |
: AANoFreeFloating(IRP, A) {} |
0 |
| 2391 |
|
--- |
2391 |
|
--- |
| 2392 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2392 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2393 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2393 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2394 |
// TODO: Once we have call site specific value information we can provide |
--- |
2394 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 2395 |
// call site specific liveness information and then it makes |
--- |
2395 |
// call site specific liveness information and then it makes |
--- |
| 2396 |
// sense to specialize attributes for call sites arguments instead of |
--- |
2396 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 2397 |
// redirecting requests to the callee argument. |
--- |
2397 |
// redirecting requests to the callee argument. |
--- |
| 2398 |
Argument *Arg = getAssociatedArgument(); |
0 |
2398 |
Argument *Arg = getAssociatedArgument(); |
0 |
| 2399 |
if (!Arg) |
0 |
2399 |
if (!Arg) |
0 |
| 2400 |
return indicatePessimisticFixpoint(); |
0 |
2400 |
return indicatePessimisticFixpoint(); |
0 |
| 2401 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
2401 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
| 2402 |
bool IsKnown; |
--- |
2402 |
bool IsKnown; |
--- |
| 2403 |
if (AA::hasAssumedIRAttr(A, this, ArgPos, |
0 |
2403 |
if (AA::hasAssumedIRAttr(A, this, ArgPos, |
0 |
| 2404 |
DepClassTy::REQUIRED, IsKnown)) |
--- |
2404 |
DepClassTy::REQUIRED, IsKnown)) |
--- |
| 2405 |
return ChangeStatus::UNCHANGED; |
0 |
2405 |
return ChangeStatus::UNCHANGED; |
0 |
| 2406 |
return indicatePessimisticFixpoint(); |
0 |
2406 |
return indicatePessimisticFixpoint(); |
0 |
| 2407 |
} |
--- |
2407 |
} |
--- |
| 2408 |
|
--- |
2408 |
|
--- |
| 2409 |
/// See AbstractAttribute::trackStatistics() |
--- |
2409 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2410 |
void trackStatistics() const override{STATS_DECLTRACK_CSARG_ATTR(nofree)}; |
0 |
2410 |
void trackStatistics() const override{STATS_DECLTRACK_CSARG_ATTR(nofree)}; |
0 |
| 2411 |
}; |
--- |
2411 |
}; |
--- |
| 2412 |
|
--- |
2412 |
|
--- |
| 2413 |
/// NoFree attribute for function return value. |
--- |
2413 |
/// NoFree attribute for function return value. |
--- |
| 2414 |
struct AANoFreeReturned final : AANoFreeFloating { |
--- |
2414 |
struct AANoFreeReturned final : AANoFreeFloating { |
--- |
| 2415 |
AANoFreeReturned(const IRPosition &IRP, Attributor &A) |
0 |
2415 |
AANoFreeReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 2416 |
: AANoFreeFloating(IRP, A) { |
0 |
2416 |
: AANoFreeFloating(IRP, A) { |
0 |
| 2417 |
llvm_unreachable("NoFree is not applicable to function returns!"); |
0 |
2417 |
llvm_unreachable("NoFree is not applicable to function returns!"); |
0 |
| 2418 |
} |
--- |
2418 |
} |
--- |
| 2419 |
|
--- |
2419 |
|
--- |
| 2420 |
/// See AbstractAttribute::initialize(...). |
--- |
2420 |
/// See AbstractAttribute::initialize(...). |
--- |
| 2421 |
void initialize(Attributor &A) override { |
0 |
2421 |
void initialize(Attributor &A) override { |
0 |
| 2422 |
llvm_unreachable("NoFree is not applicable to function returns!"); |
0 |
2422 |
llvm_unreachable("NoFree is not applicable to function returns!"); |
0 |
| 2423 |
} |
--- |
2423 |
} |
--- |
| 2424 |
|
--- |
2424 |
|
--- |
| 2425 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2425 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2426 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2426 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2427 |
llvm_unreachable("NoFree is not applicable to function returns!"); |
0 |
2427 |
llvm_unreachable("NoFree is not applicable to function returns!"); |
0 |
| 2428 |
} |
--- |
2428 |
} |
--- |
| 2429 |
|
--- |
2429 |
|
--- |
| 2430 |
/// See AbstractAttribute::trackStatistics() |
--- |
2430 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2431 |
void trackStatistics() const override {} |
0 |
2431 |
void trackStatistics() const override {} |
0 |
| 2432 |
}; |
--- |
2432 |
}; |
--- |
| 2433 |
|
--- |
2433 |
|
--- |
| 2434 |
/// NoFree attribute deduction for a call site return value. |
--- |
2434 |
/// NoFree attribute deduction for a call site return value. |
--- |
| 2435 |
struct AANoFreeCallSiteReturned final : AANoFreeFloating { |
--- |
2435 |
struct AANoFreeCallSiteReturned final : AANoFreeFloating { |
--- |
| 2436 |
AANoFreeCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
2436 |
AANoFreeCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 2437 |
: AANoFreeFloating(IRP, A) {} |
0 |
2437 |
: AANoFreeFloating(IRP, A) {} |
0 |
| 2438 |
|
--- |
2438 |
|
--- |
| 2439 |
ChangeStatus manifest(Attributor &A) override { |
0 |
2439 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 2440 |
return ChangeStatus::UNCHANGED; |
0 |
2440 |
return ChangeStatus::UNCHANGED; |
0 |
| 2441 |
} |
--- |
2441 |
} |
--- |
| 2442 |
/// See AbstractAttribute::trackStatistics() |
--- |
2442 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2443 |
void trackStatistics() const override { STATS_DECLTRACK_CSRET_ATTR(nofree) } |
0 |
2443 |
void trackStatistics() const override { STATS_DECLTRACK_CSRET_ATTR(nofree) } |
0 |
| 2444 |
}; |
--- |
2444 |
}; |
--- |
| 2445 |
} // namespace |
--- |
2445 |
} // namespace |
--- |
| 2446 |
|
--- |
2446 |
|
--- |
| 2447 |
/// ------------------------ NonNull Argument Attribute ------------------------ |
--- |
2447 |
/// ------------------------ NonNull Argument Attribute ------------------------ |
--- |
| 2448 |
|
--- |
2448 |
|
--- |
| 2449 |
bool AANonNull::isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
2449 |
bool AANonNull::isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
| 2450 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
2450 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 2451 |
bool IgnoreSubsumingPositions) { |
--- |
2451 |
bool IgnoreSubsumingPositions) { |
--- |
| 2452 |
SmallVector AttrKinds; |
0 |
2452 |
SmallVector AttrKinds; |
0 |
| 2453 |
AttrKinds.push_back(Attribute::NonNull); |
0 |
2453 |
AttrKinds.push_back(Attribute::NonNull); |
0 |
| 2454 |
if (!NullPointerIsDefined(IRP.getAnchorScope(), |
0 |
2454 |
if (!NullPointerIsDefined(IRP.getAnchorScope(), |
0 |
| 2455 |
IRP.getAssociatedType()->getPointerAddressSpace())) |
--- |
2455 |
IRP.getAssociatedType()->getPointerAddressSpace())) |
--- |
| 2456 |
AttrKinds.push_back(Attribute::Dereferenceable); |
0 |
2456 |
AttrKinds.push_back(Attribute::Dereferenceable); |
0 |
| 2457 |
if (A.hasAttr(IRP, AttrKinds, IgnoreSubsumingPositions, Attribute::NonNull)) |
0 |
2457 |
if (A.hasAttr(IRP, AttrKinds, IgnoreSubsumingPositions, Attribute::NonNull)) |
0 |
| 2458 |
return true; |
0 |
2458 |
return true; |
0 |
| 2459 |
|
--- |
2459 |
|
--- |
| 2460 |
DominatorTree *DT = nullptr; |
0 |
2460 |
DominatorTree *DT = nullptr; |
0 |
| 2461 |
AssumptionCache *AC = nullptr; |
0 |
2461 |
AssumptionCache *AC = nullptr; |
0 |
| 2462 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
2462 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
| 2463 |
if (const Function *Fn = IRP.getAnchorScope()) { |
0 |
2463 |
if (const Function *Fn = IRP.getAnchorScope()) { |
0 |
| 2464 |
if (!Fn->isDeclaration()) { |
0 |
2464 |
if (!Fn->isDeclaration()) { |
0 |
| 2465 |
DT = InfoCache.getAnalysisResultForFunction(*Fn); |
0 |
2465 |
DT = InfoCache.getAnalysisResultForFunction(*Fn); |
0 |
| 2466 |
AC = InfoCache.getAnalysisResultForFunction(*Fn); |
0 |
2466 |
AC = InfoCache.getAnalysisResultForFunction(*Fn); |
0 |
| 2467 |
} |
--- |
2467 |
} |
--- |
| 2468 |
} |
--- |
2468 |
} |
--- |
| 2469 |
|
--- |
2469 |
|
--- |
| 2470 |
SmallVector Worklist; |
0 |
2470 |
SmallVector Worklist; |
0 |
| 2471 |
if (IRP.getPositionKind() != IRP_RETURNED) { |
0 |
2471 |
if (IRP.getPositionKind() != IRP_RETURNED) { |
0 |
| 2472 |
Worklist.push_back({IRP.getAssociatedValue(), IRP.getCtxI()}); |
0 |
2472 |
Worklist.push_back({IRP.getAssociatedValue(), IRP.getCtxI()}); |
0 |
| 2473 |
} else { |
--- |
2473 |
} else { |
--- |
| 2474 |
bool UsedAssumedInformation = false; |
0 |
2474 |
bool UsedAssumedInformation = false; |
0 |
| 2475 |
if (!A.checkForAllInstructions( |
0 |
2475 |
if (!A.checkForAllInstructions( |
0 |
| 2476 |
[&](Instruction &I) { |
0 |
2476 |
[&](Instruction &I) { |
0 |
| 2477 |
Worklist.push_back({*cast(I).getReturnValue(), &I}); |
0 |
2477 |
Worklist.push_back({*cast(I).getReturnValue(), &I}); |
0 |
| 2478 |
return true; |
0 |
2478 |
return true; |
0 |
| 2479 |
}, |
--- |
2479 |
}, |
--- |
| 2480 |
IRP.getAssociatedFunction(), nullptr, {Instruction::Ret}, |
0 |
2480 |
IRP.getAssociatedFunction(), nullptr, {Instruction::Ret}, |
0 |
| 2481 |
UsedAssumedInformation)) |
--- |
2481 |
UsedAssumedInformation)) |
--- |
| 2482 |
return false; |
0 |
2482 |
return false; |
0 |
| 2483 |
} |
--- |
2483 |
} |
--- |
| 2484 |
|
--- |
2484 |
|
--- |
| 2485 |
if (llvm::any_of(Worklist, [&](AA::ValueAndContext VAC) { |
0 |
2485 |
if (llvm::any_of(Worklist, [&](AA::ValueAndContext VAC) { |
0 |
| 2486 |
return !isKnownNonZero(VAC.getValue(), A.getDataLayout(), 0, AC, |
0 |
2486 |
return !isKnownNonZero(VAC.getValue(), A.getDataLayout(), 0, AC, |
0 |
| 2487 |
VAC.getCtxI(), DT); |
0 |
2487 |
VAC.getCtxI(), DT); |
0 |
| 2488 |
})) |
--- |
2488 |
})) |
--- |
| 2489 |
return false; |
0 |
2489 |
return false; |
0 |
| 2490 |
|
--- |
2490 |
|
--- |
| 2491 |
A.manifestAttrs(IRP, {Attribute::get(IRP.getAnchorValue().getContext(), |
0 |
2491 |
A.manifestAttrs(IRP, {Attribute::get(IRP.getAnchorValue().getContext(), |
0 |
| 2492 |
Attribute::NonNull)}); |
--- |
2492 |
Attribute::NonNull)}); |
--- |
| 2493 |
return true; |
0 |
2493 |
return true; |
0 |
| 2494 |
} |
0 |
2494 |
} |
0 |
| 2495 |
|
--- |
2495 |
|
--- |
| 2496 |
namespace { |
--- |
2496 |
namespace { |
--- |
| 2497 |
static int64_t getKnownNonNullAndDerefBytesForUse( |
0 |
2497 |
static int64_t getKnownNonNullAndDerefBytesForUse( |
0 |
| 2498 |
Attributor &A, const AbstractAttribute &QueryingAA, Value &AssociatedValue, |
--- |
2498 |
Attributor &A, const AbstractAttribute &QueryingAA, Value &AssociatedValue, |
--- |
| 2499 |
const Use *U, const Instruction *I, bool &IsNonNull, bool &TrackUse) { |
--- |
2499 |
const Use *U, const Instruction *I, bool &IsNonNull, bool &TrackUse) { |
--- |
| 2500 |
TrackUse = false; |
0 |
2500 |
TrackUse = false; |
0 |
| 2501 |
|
--- |
2501 |
|
--- |
| 2502 |
const Value *UseV = U->get(); |
0 |
2502 |
const Value *UseV = U->get(); |
0 |
| 2503 |
if (!UseV->getType()->isPointerTy()) |
0 |
2503 |
if (!UseV->getType()->isPointerTy()) |
0 |
| 2504 |
return 0; |
0 |
2504 |
return 0; |
0 |
| 2505 |
|
--- |
2505 |
|
--- |
| 2506 |
// We need to follow common pointer manipulation uses to the accesses they |
--- |
2506 |
// We need to follow common pointer manipulation uses to the accesses they |
--- |
| 2507 |
// feed into. We can try to be smart to avoid looking through things we do not |
--- |
2507 |
// feed into. We can try to be smart to avoid looking through things we do not |
--- |
| 2508 |
// like for now, e.g., non-inbounds GEPs. |
--- |
2508 |
// like for now, e.g., non-inbounds GEPs. |
--- |
| 2509 |
if (isa(I)) { |
0 |
2509 |
if (isa(I)) { |
0 |
| 2510 |
TrackUse = true; |
0 |
2510 |
TrackUse = true; |
0 |
| 2511 |
return 0; |
0 |
2511 |
return 0; |
0 |
| 2512 |
} |
--- |
2512 |
} |
--- |
| 2513 |
|
--- |
2513 |
|
--- |
| 2514 |
if (isa(I)) { |
0 |
2514 |
if (isa(I)) { |
0 |
| 2515 |
TrackUse = true; |
0 |
2515 |
TrackUse = true; |
0 |
| 2516 |
return 0; |
0 |
2516 |
return 0; |
0 |
| 2517 |
} |
--- |
2517 |
} |
--- |
| 2518 |
|
--- |
2518 |
|
--- |
| 2519 |
Type *PtrTy = UseV->getType(); |
0 |
2519 |
Type *PtrTy = UseV->getType(); |
0 |
| 2520 |
const Function *F = I->getFunction(); |
0 |
2520 |
const Function *F = I->getFunction(); |
0 |
| 2521 |
bool NullPointerIsDefined = |
--- |
2521 |
bool NullPointerIsDefined = |
--- |
| 2522 |
F ? llvm::NullPointerIsDefined(F, PtrTy->getPointerAddressSpace()) : true; |
0 |
2522 |
F ? llvm::NullPointerIsDefined(F, PtrTy->getPointerAddressSpace()) : true; |
0 |
| 2523 |
const DataLayout &DL = A.getInfoCache().getDL(); |
0 |
2523 |
const DataLayout &DL = A.getInfoCache().getDL(); |
0 |
| 2524 |
if (const auto *CB = dyn_cast(I)) { |
0 |
2524 |
if (const auto *CB = dyn_cast(I)) { |
0 |
| 2525 |
if (CB->isBundleOperand(U)) { |
0 |
2525 |
if (CB->isBundleOperand(U)) { |
0 |
| 2526 |
if (RetainedKnowledge RK = getKnowledgeFromUse( |
0 |
2526 |
if (RetainedKnowledge RK = getKnowledgeFromUse( |
0 |
| 2527 |
U, {Attribute::NonNull, Attribute::Dereferenceable})) { |
0 |
2527 |
U, {Attribute::NonNull, Attribute::Dereferenceable})) { |
0 |
| 2528 |
IsNonNull |= |
0 |
2528 |
IsNonNull |= |
0 |
| 2529 |
(RK.AttrKind == Attribute::NonNull || !NullPointerIsDefined); |
0 |
2529 |
(RK.AttrKind == Attribute::NonNull || !NullPointerIsDefined); |
0 |
| 2530 |
return RK.ArgValue; |
0 |
2530 |
return RK.ArgValue; |
0 |
| 2531 |
} |
--- |
2531 |
} |
--- |
| 2532 |
return 0; |
0 |
2532 |
return 0; |
0 |
| 2533 |
} |
--- |
2533 |
} |
--- |
| 2534 |
|
--- |
2534 |
|
--- |
| 2535 |
if (CB->isCallee(U)) { |
0 |
2535 |
if (CB->isCallee(U)) { |
0 |
| 2536 |
IsNonNull |= !NullPointerIsDefined; |
0 |
2536 |
IsNonNull |= !NullPointerIsDefined; |
0 |
| 2537 |
return 0; |
0 |
2537 |
return 0; |
0 |
| 2538 |
} |
--- |
2538 |
} |
--- |
| 2539 |
|
--- |
2539 |
|
--- |
| 2540 |
unsigned ArgNo = CB->getArgOperandNo(U); |
0 |
2540 |
unsigned ArgNo = CB->getArgOperandNo(U); |
0 |
| 2541 |
IRPosition IRP = IRPosition::callsite_argument(*CB, ArgNo); |
0 |
2541 |
IRPosition IRP = IRPosition::callsite_argument(*CB, ArgNo); |
0 |
| 2542 |
// As long as we only use known information there is no need to track |
--- |
2542 |
// As long as we only use known information there is no need to track |
--- |
| 2543 |
// dependences here. |
--- |
2543 |
// dependences here. |
--- |
| 2544 |
bool IsKnownNonNull; |
--- |
2544 |
bool IsKnownNonNull; |
--- |
| 2545 |
AA::hasAssumedIRAttr(A, &QueryingAA, IRP, |
0 |
2545 |
AA::hasAssumedIRAttr(A, &QueryingAA, IRP, |
0 |
| 2546 |
DepClassTy::NONE, IsKnownNonNull); |
--- |
2546 |
DepClassTy::NONE, IsKnownNonNull); |
--- |
| 2547 |
IsNonNull |= IsKnownNonNull; |
0 |
2547 |
IsNonNull |= IsKnownNonNull; |
0 |
| 2548 |
auto *DerefAA = |
--- |
2548 |
auto *DerefAA = |
--- |
| 2549 |
A.getAAFor(QueryingAA, IRP, DepClassTy::NONE); |
0 |
2549 |
A.getAAFor(QueryingAA, IRP, DepClassTy::NONE); |
0 |
| 2550 |
return DerefAA ? DerefAA->getKnownDereferenceableBytes() : 0; |
0 |
2550 |
return DerefAA ? DerefAA->getKnownDereferenceableBytes() : 0; |
0 |
| 2551 |
} |
--- |
2551 |
} |
--- |
| 2552 |
|
--- |
2552 |
|
--- |
| 2553 |
std::optional Loc = MemoryLocation::getOrNone(I); |
0 |
2553 |
std::optional Loc = MemoryLocation::getOrNone(I); |
0 |
| 2554 |
if (!Loc || Loc->Ptr != UseV || !Loc->Size.isPrecise() || I->isVolatile()) |
0 |
2554 |
if (!Loc || Loc->Ptr != UseV || !Loc->Size.isPrecise() || I->isVolatile()) |
0 |
| 2555 |
return 0; |
0 |
2555 |
return 0; |
0 |
| 2556 |
|
--- |
2556 |
|
--- |
| 2557 |
int64_t Offset; |
--- |
2557 |
int64_t Offset; |
--- |
| 2558 |
const Value *Base = |
--- |
2558 |
const Value *Base = |
--- |
| 2559 |
getMinimalBaseOfPointer(A, QueryingAA, Loc->Ptr, Offset, DL); |
0 |
2559 |
getMinimalBaseOfPointer(A, QueryingAA, Loc->Ptr, Offset, DL); |
0 |
| 2560 |
if (Base && Base == &AssociatedValue) { |
0 |
2560 |
if (Base && Base == &AssociatedValue) { |
0 |
| 2561 |
int64_t DerefBytes = Loc->Size.getValue() + Offset; |
0 |
2561 |
int64_t DerefBytes = Loc->Size.getValue() + Offset; |
0 |
| 2562 |
IsNonNull |= !NullPointerIsDefined; |
0 |
2562 |
IsNonNull |= !NullPointerIsDefined; |
0 |
| 2563 |
return std::max(int64_t(0), DerefBytes); |
0 |
2563 |
return std::max(int64_t(0), DerefBytes); |
0 |
| 2564 |
} |
--- |
2564 |
} |
--- |
| 2565 |
|
--- |
2565 |
|
--- |
| 2566 |
/// Corner case when an offset is 0. |
--- |
2566 |
/// Corner case when an offset is 0. |
--- |
| 2567 |
Base = GetPointerBaseWithConstantOffset(Loc->Ptr, Offset, DL, |
0 |
2567 |
Base = GetPointerBaseWithConstantOffset(Loc->Ptr, Offset, DL, |
0 |
| 2568 |
/*AllowNonInbounds*/ true); |
--- |
2568 |
/*AllowNonInbounds*/ true); |
--- |
| 2569 |
if (Base && Base == &AssociatedValue && Offset == 0) { |
0 |
2569 |
if (Base && Base == &AssociatedValue && Offset == 0) { |
0 |
| 2570 |
int64_t DerefBytes = Loc->Size.getValue(); |
0 |
2570 |
int64_t DerefBytes = Loc->Size.getValue(); |
0 |
| 2571 |
IsNonNull |= !NullPointerIsDefined; |
0 |
2571 |
IsNonNull |= !NullPointerIsDefined; |
0 |
| 2572 |
return std::max(int64_t(0), DerefBytes); |
0 |
2572 |
return std::max(int64_t(0), DerefBytes); |
0 |
| 2573 |
} |
--- |
2573 |
} |
--- |
| 2574 |
|
--- |
2574 |
|
--- |
| 2575 |
return 0; |
0 |
2575 |
return 0; |
0 |
| 2576 |
} |
--- |
2576 |
} |
--- |
| 2577 |
|
--- |
2577 |
|
--- |
| 2578 |
struct AANonNullImpl : AANonNull { |
--- |
2578 |
struct AANonNullImpl : AANonNull { |
--- |
| 2579 |
AANonNullImpl(const IRPosition &IRP, Attributor &A) : AANonNull(IRP, A) {} |
0 |
2579 |
AANonNullImpl(const IRPosition &IRP, Attributor &A) : AANonNull(IRP, A) {} |
0 |
| 2580 |
|
--- |
2580 |
|
--- |
| 2581 |
/// See AbstractAttribute::initialize(...). |
--- |
2581 |
/// See AbstractAttribute::initialize(...). |
--- |
| 2582 |
void initialize(Attributor &A) override { |
0 |
2582 |
void initialize(Attributor &A) override { |
0 |
| 2583 |
Value &V = *getAssociatedValue().stripPointerCasts(); |
0 |
2583 |
Value &V = *getAssociatedValue().stripPointerCasts(); |
0 |
| 2584 |
if (isa(V)) { |
0 |
2584 |
if (isa(V)) { |
0 |
| 2585 |
indicatePessimisticFixpoint(); |
0 |
2585 |
indicatePessimisticFixpoint(); |
0 |
| 2586 |
return; |
0 |
2586 |
return; |
0 |
| 2587 |
} |
--- |
2587 |
} |
--- |
| 2588 |
|
--- |
2588 |
|
--- |
| 2589 |
if (Instruction *CtxI = getCtxI()) |
0 |
2589 |
if (Instruction *CtxI = getCtxI()) |
0 |
| 2590 |
followUsesInMBEC(*this, A, getState(), *CtxI); |
0 |
2590 |
followUsesInMBEC(*this, A, getState(), *CtxI); |
0 |
| 2591 |
} |
--- |
2591 |
} |
--- |
| 2592 |
|
--- |
2592 |
|
--- |
| 2593 |
/// See followUsesInMBEC |
--- |
2593 |
/// See followUsesInMBEC |
--- |
| 2594 |
bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I, |
0 |
2594 |
bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I, |
0 |
| 2595 |
AANonNull::StateType &State) { |
--- |
2595 |
AANonNull::StateType &State) { |
--- |
| 2596 |
bool IsNonNull = false; |
0 |
2596 |
bool IsNonNull = false; |
0 |
| 2597 |
bool TrackUse = false; |
0 |
2597 |
bool TrackUse = false; |
0 |
| 2598 |
getKnownNonNullAndDerefBytesForUse(A, *this, getAssociatedValue(), U, I, |
0 |
2598 |
getKnownNonNullAndDerefBytesForUse(A, *this, getAssociatedValue(), U, I, |
0 |
| 2599 |
IsNonNull, TrackUse); |
--- |
2599 |
IsNonNull, TrackUse); |
--- |
| 2600 |
State.setKnown(IsNonNull); |
0 |
2600 |
State.setKnown(IsNonNull); |
0 |
| 2601 |
return TrackUse; |
0 |
2601 |
return TrackUse; |
0 |
| 2602 |
} |
--- |
2602 |
} |
--- |
| 2603 |
|
--- |
2603 |
|
--- |
| 2604 |
/// See AbstractAttribute::getAsStr(). |
--- |
2604 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 2605 |
const std::string getAsStr(Attributor *A) const override { |
0 |
2605 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 2606 |
return getAssumed() ? "nonnull" : "may-null"; |
0 |
2606 |
return getAssumed() ? "nonnull" : "may-null"; |
0 |
| 2607 |
} |
--- |
2607 |
} |
--- |
| 2608 |
}; |
--- |
2608 |
}; |
--- |
| 2609 |
|
--- |
2609 |
|
--- |
| 2610 |
/// NonNull attribute for a floating value. |
--- |
2610 |
/// NonNull attribute for a floating value. |
--- |
| 2611 |
struct AANonNullFloating : public AANonNullImpl { |
--- |
2611 |
struct AANonNullFloating : public AANonNullImpl { |
--- |
| 2612 |
AANonNullFloating(const IRPosition &IRP, Attributor &A) |
0 |
2612 |
AANonNullFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 2613 |
: AANonNullImpl(IRP, A) {} |
0 |
2613 |
: AANonNullImpl(IRP, A) {} |
0 |
| 2614 |
|
--- |
2614 |
|
--- |
| 2615 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2615 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2616 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2616 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2617 |
auto CheckIRP = [&](const IRPosition &IRP) { |
0 |
2617 |
auto CheckIRP = [&](const IRPosition &IRP) { |
0 |
| 2618 |
bool IsKnownNonNull; |
--- |
2618 |
bool IsKnownNonNull; |
--- |
| 2619 |
return AA::hasAssumedIRAttr( |
0 |
2619 |
return AA::hasAssumedIRAttr( |
0 |
| 2620 |
A, *this, IRP, DepClassTy::OPTIONAL, IsKnownNonNull); |
0 |
2620 |
A, *this, IRP, DepClassTy::OPTIONAL, IsKnownNonNull); |
0 |
| 2621 |
}; |
0 |
2621 |
}; |
0 |
| 2622 |
|
--- |
2622 |
|
--- |
| 2623 |
bool Stripped; |
--- |
2623 |
bool Stripped; |
--- |
| 2624 |
bool UsedAssumedInformation = false; |
0 |
2624 |
bool UsedAssumedInformation = false; |
0 |
| 2625 |
Value *AssociatedValue = &getAssociatedValue(); |
0 |
2625 |
Value *AssociatedValue = &getAssociatedValue(); |
0 |
| 2626 |
SmallVector Values; |
0 |
2626 |
SmallVector Values; |
0 |
| 2627 |
if (!A.getAssumedSimplifiedValues(getIRPosition(), *this, Values, |
0 |
2627 |
if (!A.getAssumedSimplifiedValues(getIRPosition(), *this, Values, |
0 |
| 2628 |
AA::AnyScope, UsedAssumedInformation)) |
--- |
2628 |
AA::AnyScope, UsedAssumedInformation)) |
--- |
| 2629 |
Stripped = false; |
0 |
2629 |
Stripped = false; |
0 |
| 2630 |
else |
--- |
2630 |
else |
--- |
| 2631 |
Stripped = |
0 |
2631 |
Stripped = |
0 |
| 2632 |
Values.size() != 1 || Values.front().getValue() != AssociatedValue; |
0 |
2632 |
Values.size() != 1 || Values.front().getValue() != AssociatedValue; |
0 |
| 2633 |
|
--- |
2633 |
|
--- |
| 2634 |
if (!Stripped) { |
0 |
2634 |
if (!Stripped) { |
0 |
| 2635 |
bool IsKnown; |
--- |
2635 |
bool IsKnown; |
--- |
| 2636 |
if (auto *PHI = dyn_cast(AssociatedValue)) |
0 |
2636 |
if (auto *PHI = dyn_cast(AssociatedValue)) |
0 |
| 2637 |
if (llvm::all_of(PHI->incoming_values(), [&](Value *Op) { |
0 |
2637 |
if (llvm::all_of(PHI->incoming_values(), [&](Value *Op) { |
0 |
| 2638 |
return AA::hasAssumedIRAttr( |
0 |
2638 |
return AA::hasAssumedIRAttr( |
0 |
| 2639 |
A, this, IRPosition::value(*Op), DepClassTy::OPTIONAL, |
0 |
2639 |
A, this, IRPosition::value(*Op), DepClassTy::OPTIONAL, |
0 |
| 2640 |
IsKnown); |
0 |
2640 |
IsKnown); |
0 |
| 2641 |
})) |
--- |
2641 |
})) |
--- |
| 2642 |
return ChangeStatus::UNCHANGED; |
0 |
2642 |
return ChangeStatus::UNCHANGED; |
0 |
| 2643 |
if (auto *Select = dyn_cast(AssociatedValue)) |
0 |
2643 |
if (auto *Select = dyn_cast(AssociatedValue)) |
0 |
| 2644 |
if (AA::hasAssumedIRAttr( |
0 |
2644 |
if (AA::hasAssumedIRAttr( |
0 |
| 2645 |
A, this, IRPosition::value(*Select->getFalseValue()), |
0 |
2645 |
A, this, IRPosition::value(*Select->getFalseValue()), |
0 |
| 2646 |
DepClassTy::OPTIONAL, IsKnown) && |
0 |
2646 |
DepClassTy::OPTIONAL, IsKnown) && |
0 |
| 2647 |
AA::hasAssumedIRAttr( |
0 |
2647 |
AA::hasAssumedIRAttr( |
0 |
| 2648 |
A, this, IRPosition::value(*Select->getTrueValue()), |
0 |
2648 |
A, this, IRPosition::value(*Select->getTrueValue()), |
0 |
| 2649 |
DepClassTy::OPTIONAL, IsKnown)) |
--- |
2649 |
DepClassTy::OPTIONAL, IsKnown)) |
--- |
| 2650 |
return ChangeStatus::UNCHANGED; |
0 |
2650 |
return ChangeStatus::UNCHANGED; |
0 |
| 2651 |
|
--- |
2651 |
|
--- |
| 2652 |
// If we haven't stripped anything we might still be able to use a |
--- |
2652 |
// If we haven't stripped anything we might still be able to use a |
--- |
| 2653 |
// different AA, but only if the IRP changes. Effectively when we |
--- |
2653 |
// different AA, but only if the IRP changes. Effectively when we |
--- |
| 2654 |
// interpret this not as a call site value but as a floating/argument |
--- |
2654 |
// interpret this not as a call site value but as a floating/argument |
--- |
| 2655 |
// value. |
--- |
2655 |
// value. |
--- |
| 2656 |
const IRPosition AVIRP = IRPosition::value(*AssociatedValue); |
0 |
2656 |
const IRPosition AVIRP = IRPosition::value(*AssociatedValue); |
0 |
| 2657 |
if (AVIRP == getIRPosition() || !CheckIRP(AVIRP)) |
0 |
2657 |
if (AVIRP == getIRPosition() || !CheckIRP(AVIRP)) |
0 |
| 2658 |
return indicatePessimisticFixpoint(); |
0 |
2658 |
return indicatePessimisticFixpoint(); |
0 |
| 2659 |
return ChangeStatus::UNCHANGED; |
0 |
2659 |
return ChangeStatus::UNCHANGED; |
0 |
| 2660 |
} |
--- |
2660 |
} |
--- |
| 2661 |
|
--- |
2661 |
|
--- |
| 2662 |
for (const auto &VAC : Values) |
0 |
2662 |
for (const auto &VAC : Values) |
0 |
| 2663 |
if (!CheckIRP(IRPosition::value(*VAC.getValue()))) |
0 |
2663 |
if (!CheckIRP(IRPosition::value(*VAC.getValue()))) |
0 |
| 2664 |
return indicatePessimisticFixpoint(); |
0 |
2664 |
return indicatePessimisticFixpoint(); |
0 |
| 2665 |
|
--- |
2665 |
|
--- |
| 2666 |
return ChangeStatus::UNCHANGED; |
0 |
2666 |
return ChangeStatus::UNCHANGED; |
0 |
| 2667 |
} |
0 |
2667 |
} |
0 |
| 2668 |
|
--- |
2668 |
|
--- |
| 2669 |
/// See AbstractAttribute::trackStatistics() |
--- |
2669 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2670 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(nonnull) } |
0 |
2670 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(nonnull) } |
0 |
| 2671 |
}; |
--- |
2671 |
}; |
--- |
| 2672 |
|
--- |
2672 |
|
--- |
| 2673 |
/// NonNull attribute for function return value. |
--- |
2673 |
/// NonNull attribute for function return value. |
--- |
| 2674 |
struct AANonNullReturned final |
--- |
2674 |
struct AANonNullReturned final |
--- |
| 2675 |
: AAReturnedFromReturnedValues
| --- |
2675 |
: AAReturnedFromReturnedValues
| --- |
| |
| 2676 |
false, AANonNull::IRAttributeKind, false> { |
--- |
2676 |
false, AANonNull::IRAttributeKind, false> { |
--- |
| 2677 |
AANonNullReturned(const IRPosition &IRP, Attributor &A) |
0 |
2677 |
AANonNullReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 2678 |
: AAReturnedFromReturnedValues
| --- |
2678 |
: AAReturnedFromReturnedValues
| --- |
| |
| 2679 |
false, Attribute::NonNull, false>(IRP, A) { |
0 |
2679 |
false, Attribute::NonNull, false>(IRP, A) { |
0 |
| 2680 |
} |
0 |
2680 |
} |
0 |
| 2681 |
|
--- |
2681 |
|
--- |
| 2682 |
/// See AbstractAttribute::getAsStr(). |
--- |
2682 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 2683 |
const std::string getAsStr(Attributor *A) const override { |
0 |
2683 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 2684 |
return getAssumed() ? "nonnull" : "may-null"; |
0 |
2684 |
return getAssumed() ? "nonnull" : "may-null"; |
0 |
| 2685 |
} |
--- |
2685 |
} |
--- |
| 2686 |
|
--- |
2686 |
|
--- |
| 2687 |
/// See AbstractAttribute::trackStatistics() |
--- |
2687 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2688 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(nonnull) } |
0 |
2688 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(nonnull) } |
0 |
| 2689 |
}; |
--- |
2689 |
}; |
--- |
| 2690 |
|
--- |
2690 |
|
--- |
| 2691 |
/// NonNull attribute for function argument. |
--- |
2691 |
/// NonNull attribute for function argument. |
--- |
| 2692 |
struct AANonNullArgument final |
--- |
2692 |
struct AANonNullArgument final |
--- |
| 2693 |
: AAArgumentFromCallSiteArguments
| --- |
2693 |
: AAArgumentFromCallSiteArguments
| --- |
| |
| 2694 |
AANonNull::StateType, false, |
--- |
2694 |
AANonNull::StateType, false, |
--- |
| 2695 |
AANonNull::IRAttributeKind> { |
--- |
2695 |
AANonNull::IRAttributeKind> { |
--- |
| 2696 |
AANonNullArgument(const IRPosition &IRP, Attributor &A) |
0 |
2696 |
AANonNullArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 2697 |
: AAArgumentFromCallSiteArguments
| --- |
2697 |
: AAArgumentFromCallSiteArguments
| --- |
| |
| 2698 |
AANonNull::StateType, false, |
--- |
2698 |
AANonNull::StateType, false, |
--- |
| 2699 |
AANonNull::IRAttributeKind>(IRP, A) {} |
0 |
2699 |
AANonNull::IRAttributeKind>(IRP, A) {} |
0 |
| 2700 |
|
--- |
2700 |
|
--- |
| 2701 |
/// See AbstractAttribute::trackStatistics() |
--- |
2701 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2702 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(nonnull) } |
0 |
2702 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(nonnull) } |
0 |
| 2703 |
}; |
--- |
2703 |
}; |
--- |
| 2704 |
|
--- |
2704 |
|
--- |
| 2705 |
struct AANonNullCallSiteArgument final : AANonNullFloating { |
--- |
2705 |
struct AANonNullCallSiteArgument final : AANonNullFloating { |
--- |
| 2706 |
AANonNullCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
2706 |
AANonNullCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 2707 |
: AANonNullFloating(IRP, A) {} |
0 |
2707 |
: AANonNullFloating(IRP, A) {} |
0 |
| 2708 |
|
--- |
2708 |
|
--- |
| 2709 |
/// See AbstractAttribute::trackStatistics() |
--- |
2709 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2710 |
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(nonnull) } |
0 |
2710 |
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(nonnull) } |
0 |
| 2711 |
}; |
--- |
2711 |
}; |
--- |
| 2712 |
|
--- |
2712 |
|
--- |
| 2713 |
/// NonNull attribute for a call site return position. |
--- |
2713 |
/// NonNull attribute for a call site return position. |
--- |
| 2714 |
struct AANonNullCallSiteReturned final |
--- |
2714 |
struct AANonNullCallSiteReturned final |
--- |
| 2715 |
: AACallSiteReturnedFromReturned
| --- |
2715 |
: AACallSiteReturnedFromReturned
| --- |
| |
| 2716 |
AANonNull::StateType, false, |
--- |
2716 |
AANonNull::StateType, false, |
--- |
| 2717 |
AANonNull::IRAttributeKind> { |
--- |
2717 |
AANonNull::IRAttributeKind> { |
--- |
| 2718 |
AANonNullCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
2718 |
AANonNullCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 2719 |
: AACallSiteReturnedFromReturned
| --- |
2719 |
: AACallSiteReturnedFromReturned
| --- |
| |
| 2720 |
AANonNull::StateType, false, |
--- |
2720 |
AANonNull::StateType, false, |
--- |
| 2721 |
AANonNull::IRAttributeKind>(IRP, A) {} |
0 |
2721 |
AANonNull::IRAttributeKind>(IRP, A) {} |
0 |
| 2722 |
|
--- |
2722 |
|
--- |
| 2723 |
/// See AbstractAttribute::trackStatistics() |
--- |
2723 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2724 |
void trackStatistics() const override { STATS_DECLTRACK_CSRET_ATTR(nonnull) } |
0 |
2724 |
void trackStatistics() const override { STATS_DECLTRACK_CSRET_ATTR(nonnull) } |
0 |
| 2725 |
}; |
--- |
2725 |
}; |
--- |
| 2726 |
} // namespace |
--- |
2726 |
} // namespace |
--- |
| 2727 |
|
--- |
2727 |
|
--- |
| 2728 |
/// ------------------------ Must-Progress Attributes -------------------------- |
--- |
2728 |
/// ------------------------ Must-Progress Attributes -------------------------- |
--- |
| 2729 |
namespace { |
--- |
2729 |
namespace { |
--- |
| 2730 |
struct AAMustProgressImpl : public AAMustProgress { |
--- |
2730 |
struct AAMustProgressImpl : public AAMustProgress { |
--- |
| 2731 |
AAMustProgressImpl(const IRPosition &IRP, Attributor &A) |
0 |
2731 |
AAMustProgressImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 2732 |
: AAMustProgress(IRP, A) {} |
0 |
2732 |
: AAMustProgress(IRP, A) {} |
0 |
| 2733 |
|
--- |
2733 |
|
--- |
| 2734 |
/// See AbstractAttribute::initialize(...). |
--- |
2734 |
/// See AbstractAttribute::initialize(...). |
--- |
| 2735 |
void initialize(Attributor &A) override { |
0 |
2735 |
void initialize(Attributor &A) override { |
0 |
| 2736 |
bool IsKnown; |
--- |
2736 |
bool IsKnown; |
--- |
| 2737 |
assert(!AA::hasAssumedIRAttr( |
0 |
2737 |
assert(!AA::hasAssumedIRAttr( |
0 |
| 2738 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
2738 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
| 2739 |
(void)IsKnown; |
--- |
2739 |
(void)IsKnown; |
--- |
| 2740 |
} |
0 |
2740 |
} |
0 |
| 2741 |
|
--- |
2741 |
|
--- |
| 2742 |
/// See AbstractAttribute::getAsStr() |
--- |
2742 |
/// See AbstractAttribute::getAsStr() |
--- |
| 2743 |
const std::string getAsStr(Attributor *A) const override { |
0 |
2743 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 2744 |
return getAssumed() ? "mustprogress" : "may-not-progress"; |
0 |
2744 |
return getAssumed() ? "mustprogress" : "may-not-progress"; |
0 |
| 2745 |
} |
--- |
2745 |
} |
--- |
| 2746 |
}; |
--- |
2746 |
}; |
--- |
| 2747 |
|
--- |
2747 |
|
--- |
| 2748 |
struct AAMustProgressFunction final : AAMustProgressImpl { |
--- |
2748 |
struct AAMustProgressFunction final : AAMustProgressImpl { |
--- |
| 2749 |
AAMustProgressFunction(const IRPosition &IRP, Attributor &A) |
0 |
2749 |
AAMustProgressFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 2750 |
: AAMustProgressImpl(IRP, A) {} |
0 |
2750 |
: AAMustProgressImpl(IRP, A) {} |
0 |
| 2751 |
|
--- |
2751 |
|
--- |
| 2752 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2752 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2753 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2753 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2754 |
bool IsKnown; |
--- |
2754 |
bool IsKnown; |
--- |
| 2755 |
if (AA::hasAssumedIRAttr( |
0 |
2755 |
if (AA::hasAssumedIRAttr( |
0 |
| 2756 |
A, this, getIRPosition(), DepClassTy::OPTIONAL, IsKnown)) { |
0 |
2756 |
A, this, getIRPosition(), DepClassTy::OPTIONAL, IsKnown)) { |
0 |
| 2757 |
if (IsKnown) |
0 |
2757 |
if (IsKnown) |
0 |
| 2758 |
return indicateOptimisticFixpoint(); |
0 |
2758 |
return indicateOptimisticFixpoint(); |
0 |
| 2759 |
return ChangeStatus::UNCHANGED; |
0 |
2759 |
return ChangeStatus::UNCHANGED; |
0 |
| 2760 |
} |
--- |
2760 |
} |
--- |
| 2761 |
|
--- |
2761 |
|
--- |
| 2762 |
auto CheckForMustProgress = [&](AbstractCallSite ACS) { |
0 |
2762 |
auto CheckForMustProgress = [&](AbstractCallSite ACS) { |
0 |
| 2763 |
IRPosition IPos = IRPosition::callsite_function(*ACS.getInstruction()); |
0 |
2763 |
IRPosition IPos = IRPosition::callsite_function(*ACS.getInstruction()); |
0 |
| 2764 |
bool IsKnownMustProgress; |
--- |
2764 |
bool IsKnownMustProgress; |
--- |
| 2765 |
return AA::hasAssumedIRAttr( |
0 |
2765 |
return AA::hasAssumedIRAttr( |
0 |
| 2766 |
A, this, IPos, DepClassTy::REQUIRED, IsKnownMustProgress, |
0 |
2766 |
A, this, IPos, DepClassTy::REQUIRED, IsKnownMustProgress, |
0 |
| 2767 |
/* IgnoreSubsumingPositions */ true); |
0 |
2767 |
/* IgnoreSubsumingPositions */ true); |
0 |
| 2768 |
}; |
0 |
2768 |
}; |
0 |
| 2769 |
|
--- |
2769 |
|
--- |
| 2770 |
bool AllCallSitesKnown = true; |
0 |
2770 |
bool AllCallSitesKnown = true; |
0 |
| 2771 |
if (!A.checkForAllCallSites(CheckForMustProgress, *this, |
0 |
2771 |
if (!A.checkForAllCallSites(CheckForMustProgress, *this, |
0 |
| 2772 |
/* RequireAllCallSites */ true, |
--- |
2772 |
/* RequireAllCallSites */ true, |
--- |
| 2773 |
AllCallSitesKnown)) |
--- |
2773 |
AllCallSitesKnown)) |
--- |
| 2774 |
return indicatePessimisticFixpoint(); |
0 |
2774 |
return indicatePessimisticFixpoint(); |
0 |
| 2775 |
|
--- |
2775 |
|
--- |
| 2776 |
return ChangeStatus::UNCHANGED; |
0 |
2776 |
return ChangeStatus::UNCHANGED; |
0 |
| 2777 |
} |
--- |
2777 |
} |
--- |
| 2778 |
|
--- |
2778 |
|
--- |
| 2779 |
/// See AbstractAttribute::trackStatistics() |
--- |
2779 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2780 |
void trackStatistics() const override { |
0 |
2780 |
void trackStatistics() const override { |
0 |
| 2781 |
STATS_DECLTRACK_FN_ATTR(mustprogress) |
0 |
2781 |
STATS_DECLTRACK_FN_ATTR(mustprogress) |
0 |
| 2782 |
} |
0 |
2782 |
} |
0 |
| 2783 |
}; |
--- |
2783 |
}; |
--- |
| 2784 |
|
--- |
2784 |
|
--- |
| 2785 |
/// MustProgress attribute deduction for a call sites. |
--- |
2785 |
/// MustProgress attribute deduction for a call sites. |
--- |
| 2786 |
struct AAMustProgressCallSite final : AAMustProgressImpl { |
--- |
2786 |
struct AAMustProgressCallSite final : AAMustProgressImpl { |
--- |
| 2787 |
AAMustProgressCallSite(const IRPosition &IRP, Attributor &A) |
0 |
2787 |
AAMustProgressCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 2788 |
: AAMustProgressImpl(IRP, A) {} |
0 |
2788 |
: AAMustProgressImpl(IRP, A) {} |
0 |
| 2789 |
|
--- |
2789 |
|
--- |
| 2790 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2790 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2791 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2791 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2792 |
// TODO: Once we have call site specific value information we can provide |
--- |
2792 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 2793 |
// call site specific liveness information and then it makes |
--- |
2793 |
// call site specific liveness information and then it makes |
--- |
| 2794 |
// sense to specialize attributes for call sites arguments instead of |
--- |
2794 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 2795 |
// redirecting requests to the callee argument. |
--- |
2795 |
// redirecting requests to the callee argument. |
--- |
| 2796 |
const IRPosition &FnPos = IRPosition::function(*getAnchorScope()); |
0 |
2796 |
const IRPosition &FnPos = IRPosition::function(*getAnchorScope()); |
0 |
| 2797 |
bool IsKnownMustProgress; |
--- |
2797 |
bool IsKnownMustProgress; |
--- |
| 2798 |
if (!AA::hasAssumedIRAttr( |
0 |
2798 |
if (!AA::hasAssumedIRAttr( |
0 |
| 2799 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownMustProgress)) |
--- |
2799 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownMustProgress)) |
--- |
| 2800 |
return indicatePessimisticFixpoint(); |
0 |
2800 |
return indicatePessimisticFixpoint(); |
0 |
| 2801 |
return ChangeStatus::UNCHANGED; |
0 |
2801 |
return ChangeStatus::UNCHANGED; |
0 |
| 2802 |
} |
--- |
2802 |
} |
--- |
| 2803 |
|
--- |
2803 |
|
--- |
| 2804 |
/// See AbstractAttribute::trackStatistics() |
--- |
2804 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2805 |
void trackStatistics() const override { |
0 |
2805 |
void trackStatistics() const override { |
0 |
| 2806 |
STATS_DECLTRACK_CS_ATTR(mustprogress); |
0 |
2806 |
STATS_DECLTRACK_CS_ATTR(mustprogress); |
0 |
| 2807 |
} |
0 |
2807 |
} |
0 |
| 2808 |
}; |
--- |
2808 |
}; |
--- |
| 2809 |
} // namespace |
--- |
2809 |
} // namespace |
--- |
| 2810 |
|
--- |
2810 |
|
--- |
| 2811 |
/// ------------------------ No-Recurse Attributes ---------------------------- |
--- |
2811 |
/// ------------------------ No-Recurse Attributes ---------------------------- |
--- |
| 2812 |
|
--- |
2812 |
|
--- |
| 2813 |
namespace { |
--- |
2813 |
namespace { |
--- |
| 2814 |
struct AANoRecurseImpl : public AANoRecurse { |
--- |
2814 |
struct AANoRecurseImpl : public AANoRecurse { |
--- |
| 2815 |
AANoRecurseImpl(const IRPosition &IRP, Attributor &A) : AANoRecurse(IRP, A) {} |
0 |
2815 |
AANoRecurseImpl(const IRPosition &IRP, Attributor &A) : AANoRecurse(IRP, A) {} |
0 |
| 2816 |
|
--- |
2816 |
|
--- |
| 2817 |
/// See AbstractAttribute::initialize(...). |
--- |
2817 |
/// See AbstractAttribute::initialize(...). |
--- |
| 2818 |
void initialize(Attributor &A) override { |
0 |
2818 |
void initialize(Attributor &A) override { |
0 |
| 2819 |
bool IsKnown; |
--- |
2819 |
bool IsKnown; |
--- |
| 2820 |
assert(!AA::hasAssumedIRAttr( |
0 |
2820 |
assert(!AA::hasAssumedIRAttr( |
0 |
| 2821 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
2821 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
| 2822 |
(void)IsKnown; |
--- |
2822 |
(void)IsKnown; |
--- |
| 2823 |
} |
0 |
2823 |
} |
0 |
| 2824 |
|
--- |
2824 |
|
--- |
| 2825 |
/// See AbstractAttribute::getAsStr() |
--- |
2825 |
/// See AbstractAttribute::getAsStr() |
--- |
| 2826 |
const std::string getAsStr(Attributor *A) const override { |
0 |
2826 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 2827 |
return getAssumed() ? "norecurse" : "may-recurse"; |
0 |
2827 |
return getAssumed() ? "norecurse" : "may-recurse"; |
0 |
| 2828 |
} |
--- |
2828 |
} |
--- |
| 2829 |
}; |
--- |
2829 |
}; |
--- |
| 2830 |
|
--- |
2830 |
|
--- |
| 2831 |
struct AANoRecurseFunction final : AANoRecurseImpl { |
--- |
2831 |
struct AANoRecurseFunction final : AANoRecurseImpl { |
--- |
| 2832 |
AANoRecurseFunction(const IRPosition &IRP, Attributor &A) |
0 |
2832 |
AANoRecurseFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 2833 |
: AANoRecurseImpl(IRP, A) {} |
0 |
2833 |
: AANoRecurseImpl(IRP, A) {} |
0 |
| 2834 |
|
--- |
2834 |
|
--- |
| 2835 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2835 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2836 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2836 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2837 |
|
--- |
2837 |
|
--- |
| 2838 |
// If all live call sites are known to be no-recurse, we are as well. |
--- |
2838 |
// If all live call sites are known to be no-recurse, we are as well. |
--- |
| 2839 |
auto CallSitePred = [&](AbstractCallSite ACS) { |
0 |
2839 |
auto CallSitePred = [&](AbstractCallSite ACS) { |
0 |
| 2840 |
bool IsKnownNoRecurse; |
--- |
2840 |
bool IsKnownNoRecurse; |
--- |
| 2841 |
if (!AA::hasAssumedIRAttr( |
0 |
2841 |
if (!AA::hasAssumedIRAttr( |
0 |
| 2842 |
A, this, |
0 |
2842 |
A, this, |
0 |
| 2843 |
IRPosition::function(*ACS.getInstruction()->getFunction()), |
0 |
2843 |
IRPosition::function(*ACS.getInstruction()->getFunction()), |
0 |
| 2844 |
DepClassTy::NONE, IsKnownNoRecurse)) |
--- |
2844 |
DepClassTy::NONE, IsKnownNoRecurse)) |
--- |
| 2845 |
return false; |
0 |
2845 |
return false; |
0 |
| 2846 |
return IsKnownNoRecurse; |
0 |
2846 |
return IsKnownNoRecurse; |
0 |
| 2847 |
}; |
0 |
2847 |
}; |
0 |
| 2848 |
bool UsedAssumedInformation = false; |
0 |
2848 |
bool UsedAssumedInformation = false; |
0 |
| 2849 |
if (A.checkForAllCallSites(CallSitePred, *this, true, |
0 |
2849 |
if (A.checkForAllCallSites(CallSitePred, *this, true, |
0 |
| 2850 |
UsedAssumedInformation)) { |
--- |
2850 |
UsedAssumedInformation)) { |
--- |
| 2851 |
// If we know all call sites and all are known no-recurse, we are done. |
--- |
2851 |
// If we know all call sites and all are known no-recurse, we are done. |
--- |
| 2852 |
// If all known call sites, which might not be all that exist, are known |
--- |
2852 |
// If all known call sites, which might not be all that exist, are known |
--- |
| 2853 |
// to be no-recurse, we are not done but we can continue to assume |
--- |
2853 |
// to be no-recurse, we are not done but we can continue to assume |
--- |
| 2854 |
// no-recurse. If one of the call sites we have not visited will become |
--- |
2854 |
// no-recurse. If one of the call sites we have not visited will become |
--- |
| 2855 |
// live, another update is triggered. |
--- |
2855 |
// live, another update is triggered. |
--- |
| 2856 |
if (!UsedAssumedInformation) |
0 |
2856 |
if (!UsedAssumedInformation) |
0 |
| 2857 |
indicateOptimisticFixpoint(); |
0 |
2857 |
indicateOptimisticFixpoint(); |
0 |
| 2858 |
return ChangeStatus::UNCHANGED; |
0 |
2858 |
return ChangeStatus::UNCHANGED; |
0 |
| 2859 |
} |
--- |
2859 |
} |
--- |
| 2860 |
|
--- |
2860 |
|
--- |
| 2861 |
const AAInterFnReachability *EdgeReachability = |
--- |
2861 |
const AAInterFnReachability *EdgeReachability = |
--- |
| 2862 |
A.getAAFor(*this, getIRPosition(), |
0 |
2862 |
A.getAAFor(*this, getIRPosition(), |
0 |
| 2863 |
DepClassTy::REQUIRED); |
--- |
2863 |
DepClassTy::REQUIRED); |
--- |
| 2864 |
if (EdgeReachability && EdgeReachability->canReach(A, *getAnchorScope())) |
0 |
2864 |
if (EdgeReachability && EdgeReachability->canReach(A, *getAnchorScope())) |
0 |
| 2865 |
return indicatePessimisticFixpoint(); |
0 |
2865 |
return indicatePessimisticFixpoint(); |
0 |
| 2866 |
return ChangeStatus::UNCHANGED; |
0 |
2866 |
return ChangeStatus::UNCHANGED; |
0 |
| 2867 |
} |
--- |
2867 |
} |
--- |
| 2868 |
|
--- |
2868 |
|
--- |
| 2869 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(norecurse) } |
0 |
2869 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(norecurse) } |
0 |
| 2870 |
}; |
--- |
2870 |
}; |
--- |
| 2871 |
|
--- |
2871 |
|
--- |
| 2872 |
/// NoRecurse attribute deduction for a call sites. |
--- |
2872 |
/// NoRecurse attribute deduction for a call sites. |
--- |
| 2873 |
struct AANoRecurseCallSite final : AANoRecurseImpl { |
--- |
2873 |
struct AANoRecurseCallSite final : AANoRecurseImpl { |
--- |
| 2874 |
AANoRecurseCallSite(const IRPosition &IRP, Attributor &A) |
0 |
2874 |
AANoRecurseCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 2875 |
: AANoRecurseImpl(IRP, A) {} |
0 |
2875 |
: AANoRecurseImpl(IRP, A) {} |
0 |
| 2876 |
|
--- |
2876 |
|
--- |
| 2877 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2877 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2878 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2878 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2879 |
// TODO: Once we have call site specific value information we can provide |
--- |
2879 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 2880 |
// call site specific liveness information and then it makes |
--- |
2880 |
// call site specific liveness information and then it makes |
--- |
| 2881 |
// sense to specialize attributes for call sites arguments instead of |
--- |
2881 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 2882 |
// redirecting requests to the callee argument. |
--- |
2882 |
// redirecting requests to the callee argument. |
--- |
| 2883 |
Function *F = getAssociatedFunction(); |
0 |
2883 |
Function *F = getAssociatedFunction(); |
0 |
| 2884 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
2884 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
| 2885 |
bool IsKnownNoRecurse; |
--- |
2885 |
bool IsKnownNoRecurse; |
--- |
| 2886 |
if (!AA::hasAssumedIRAttr( |
0 |
2886 |
if (!AA::hasAssumedIRAttr( |
0 |
| 2887 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownNoRecurse)) |
--- |
2887 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownNoRecurse)) |
--- |
| 2888 |
return indicatePessimisticFixpoint(); |
0 |
2888 |
return indicatePessimisticFixpoint(); |
0 |
| 2889 |
return ChangeStatus::UNCHANGED; |
0 |
2889 |
return ChangeStatus::UNCHANGED; |
0 |
| 2890 |
} |
--- |
2890 |
} |
--- |
| 2891 |
|
--- |
2891 |
|
--- |
| 2892 |
/// See AbstractAttribute::trackStatistics() |
--- |
2892 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 2893 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(norecurse); } |
0 |
2893 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(norecurse); } |
0 |
| 2894 |
}; |
--- |
2894 |
}; |
--- |
| 2895 |
} // namespace |
--- |
2895 |
} // namespace |
--- |
| 2896 |
|
--- |
2896 |
|
--- |
| 2897 |
/// ------------------------ No-Convergent Attribute -------------------------- |
--- |
2897 |
/// ------------------------ No-Convergent Attribute -------------------------- |
--- |
| 2898 |
|
--- |
2898 |
|
--- |
| 2899 |
namespace { |
--- |
2899 |
namespace { |
--- |
| 2900 |
struct AANonConvergentImpl : public AANonConvergent { |
--- |
2900 |
struct AANonConvergentImpl : public AANonConvergent { |
--- |
| 2901 |
AANonConvergentImpl(const IRPosition &IRP, Attributor &A) |
0 |
2901 |
AANonConvergentImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 2902 |
: AANonConvergent(IRP, A) {} |
0 |
2902 |
: AANonConvergent(IRP, A) {} |
0 |
| 2903 |
|
--- |
2903 |
|
--- |
| 2904 |
/// See AbstractAttribute::getAsStr() |
--- |
2904 |
/// See AbstractAttribute::getAsStr() |
--- |
| 2905 |
const std::string getAsStr(Attributor *A) const override { |
0 |
2905 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 2906 |
return getAssumed() ? "non-convergent" : "may-be-convergent"; |
0 |
2906 |
return getAssumed() ? "non-convergent" : "may-be-convergent"; |
0 |
| 2907 |
} |
--- |
2907 |
} |
--- |
| 2908 |
}; |
--- |
2908 |
}; |
--- |
| 2909 |
|
--- |
2909 |
|
--- |
| 2910 |
struct AANonConvergentFunction final : AANonConvergentImpl { |
--- |
2910 |
struct AANonConvergentFunction final : AANonConvergentImpl { |
--- |
| 2911 |
AANonConvergentFunction(const IRPosition &IRP, Attributor &A) |
0 |
2911 |
AANonConvergentFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 2912 |
: AANonConvergentImpl(IRP, A) {} |
0 |
2912 |
: AANonConvergentImpl(IRP, A) {} |
0 |
| 2913 |
|
--- |
2913 |
|
--- |
| 2914 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2914 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2915 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2915 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2916 |
// If all function calls are known to not be convergent, we are not |
--- |
2916 |
// If all function calls are known to not be convergent, we are not |
--- |
| 2917 |
// convergent. |
--- |
2917 |
// convergent. |
--- |
| 2918 |
auto CalleeIsNotConvergent = [&](Instruction &Inst) { |
0 |
2918 |
auto CalleeIsNotConvergent = [&](Instruction &Inst) { |
0 |
| 2919 |
CallBase &CB = cast(Inst); |
0 |
2919 |
CallBase &CB = cast(Inst); |
0 |
| 2920 |
auto *Callee = dyn_cast_if_present(CB.getCalledOperand()); |
0 |
2920 |
auto *Callee = dyn_cast_if_present(CB.getCalledOperand()); |
0 |
| 2921 |
if (!Callee || Callee->isIntrinsic()) { |
0 |
2921 |
if (!Callee || Callee->isIntrinsic()) { |
0 |
| 2922 |
return false; |
0 |
2922 |
return false; |
0 |
| 2923 |
} |
--- |
2923 |
} |
--- |
| 2924 |
if (Callee->isDeclaration()) { |
0 |
2924 |
if (Callee->isDeclaration()) { |
0 |
| 2925 |
return !Callee->hasFnAttribute(Attribute::Convergent); |
0 |
2925 |
return !Callee->hasFnAttribute(Attribute::Convergent); |
0 |
| 2926 |
} |
--- |
2926 |
} |
--- |
| 2927 |
const auto *ConvergentAA = A.getAAFor( |
0 |
2927 |
const auto *ConvergentAA = A.getAAFor( |
0 |
| 2928 |
*this, IRPosition::function(*Callee), DepClassTy::REQUIRED); |
0 |
2928 |
*this, IRPosition::function(*Callee), DepClassTy::REQUIRED); |
0 |
| 2929 |
return ConvergentAA && ConvergentAA->isAssumedNotConvergent(); |
0 |
2929 |
return ConvergentAA && ConvergentAA->isAssumedNotConvergent(); |
0 |
| 2930 |
}; |
0 |
2930 |
}; |
0 |
| 2931 |
|
--- |
2931 |
|
--- |
| 2932 |
bool UsedAssumedInformation = false; |
0 |
2932 |
bool UsedAssumedInformation = false; |
0 |
| 2933 |
if (!A.checkForAllCallLikeInstructions(CalleeIsNotConvergent, *this, |
0 |
2933 |
if (!A.checkForAllCallLikeInstructions(CalleeIsNotConvergent, *this, |
0 |
| 2934 |
UsedAssumedInformation)) { |
--- |
2934 |
UsedAssumedInformation)) { |
--- |
| 2935 |
return indicatePessimisticFixpoint(); |
0 |
2935 |
return indicatePessimisticFixpoint(); |
0 |
| 2936 |
} |
--- |
2936 |
} |
--- |
| 2937 |
return ChangeStatus::UNCHANGED; |
0 |
2937 |
return ChangeStatus::UNCHANGED; |
0 |
| 2938 |
} |
--- |
2938 |
} |
--- |
| 2939 |
|
--- |
2939 |
|
--- |
| 2940 |
ChangeStatus manifest(Attributor &A) override { |
0 |
2940 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 2941 |
if (isKnownNotConvergent() && |
0 |
2941 |
if (isKnownNotConvergent() && |
0 |
| 2942 |
A.hasAttr(getIRPosition(), Attribute::Convergent)) { |
0 |
2942 |
A.hasAttr(getIRPosition(), Attribute::Convergent)) { |
0 |
| 2943 |
A.removeAttrs(getIRPosition(), {Attribute::Convergent}); |
0 |
2943 |
A.removeAttrs(getIRPosition(), {Attribute::Convergent}); |
0 |
| 2944 |
return ChangeStatus::CHANGED; |
0 |
2944 |
return ChangeStatus::CHANGED; |
0 |
| 2945 |
} |
--- |
2945 |
} |
--- |
| 2946 |
return ChangeStatus::UNCHANGED; |
0 |
2946 |
return ChangeStatus::UNCHANGED; |
0 |
| 2947 |
} |
--- |
2947 |
} |
--- |
| 2948 |
|
--- |
2948 |
|
--- |
| 2949 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(convergent) } |
0 |
2949 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(convergent) } |
0 |
| 2950 |
}; |
--- |
2950 |
}; |
--- |
| 2951 |
} // namespace |
--- |
2951 |
} // namespace |
--- |
| 2952 |
|
--- |
2952 |
|
--- |
| 2953 |
/// -------------------- Undefined-Behavior Attributes ------------------------ |
--- |
2953 |
/// -------------------- Undefined-Behavior Attributes ------------------------ |
--- |
| 2954 |
|
--- |
2954 |
|
--- |
| 2955 |
namespace { |
--- |
2955 |
namespace { |
--- |
| 2956 |
struct AAUndefinedBehaviorImpl : public AAUndefinedBehavior { |
--- |
2956 |
struct AAUndefinedBehaviorImpl : public AAUndefinedBehavior { |
--- |
| 2957 |
AAUndefinedBehaviorImpl(const IRPosition &IRP, Attributor &A) |
0 |
2957 |
AAUndefinedBehaviorImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 2958 |
: AAUndefinedBehavior(IRP, A) {} |
0 |
2958 |
: AAUndefinedBehavior(IRP, A) {} |
0 |
| 2959 |
|
--- |
2959 |
|
--- |
| 2960 |
/// See AbstractAttribute::updateImpl(...). |
--- |
2960 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 2961 |
// through a pointer (i.e. also branches etc.) |
--- |
2961 |
// through a pointer (i.e. also branches etc.) |
--- |
| 2962 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
2962 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 2963 |
const size_t UBPrevSize = KnownUBInsts.size(); |
0 |
2963 |
const size_t UBPrevSize = KnownUBInsts.size(); |
0 |
| 2964 |
const size_t NoUBPrevSize = AssumedNoUBInsts.size(); |
0 |
2964 |
const size_t NoUBPrevSize = AssumedNoUBInsts.size(); |
0 |
| 2965 |
|
--- |
2965 |
|
--- |
| 2966 |
auto InspectMemAccessInstForUB = [&](Instruction &I) { |
0 |
2966 |
auto InspectMemAccessInstForUB = [&](Instruction &I) { |
0 |
| 2967 |
// Lang ref now states volatile store is not UB, let's skip them. |
--- |
2967 |
// Lang ref now states volatile store is not UB, let's skip them. |
--- |
| 2968 |
if (I.isVolatile() && I.mayWriteToMemory()) |
0 |
2968 |
if (I.isVolatile() && I.mayWriteToMemory()) |
0 |
| 2969 |
return true; |
0 |
2969 |
return true; |
0 |
| 2970 |
|
--- |
2970 |
|
--- |
| 2971 |
// Skip instructions that are already saved. |
--- |
2971 |
// Skip instructions that are already saved. |
--- |
| 2972 |
if (AssumedNoUBInsts.count(&I) || KnownUBInsts.count(&I)) |
0 |
2972 |
if (AssumedNoUBInsts.count(&I) || KnownUBInsts.count(&I)) |
0 |
| 2973 |
return true; |
0 |
2973 |
return true; |
0 |
| 2974 |
|
--- |
2974 |
|
--- |
| 2975 |
// If we reach here, we know we have an instruction |
--- |
2975 |
// If we reach here, we know we have an instruction |
--- |
| 2976 |
// that accesses memory through a pointer operand, |
--- |
2976 |
// that accesses memory through a pointer operand, |
--- |
| 2977 |
// for which getPointerOperand() should give it to us. |
--- |
2977 |
// for which getPointerOperand() should give it to us. |
--- |
| 2978 |
Value *PtrOp = |
--- |
2978 |
Value *PtrOp = |
--- |
| 2979 |
const_cast(getPointerOperand(&I, /* AllowVolatile */ true)); |
0 |
2979 |
const_cast(getPointerOperand(&I, /* AllowVolatile */ true)); |
0 |
| 2980 |
assert(PtrOp && |
0 |
2980 |
assert(PtrOp && |
0 |
| 2981 |
"Expected pointer operand of memory accessing instruction"); |
--- |
2981 |
"Expected pointer operand of memory accessing instruction"); |
--- |
| 2982 |
|
--- |
2982 |
|
--- |
| 2983 |
// Either we stopped and the appropriate action was taken, |
--- |
2983 |
// Either we stopped and the appropriate action was taken, |
--- |
| 2984 |
// or we got back a simplified value to continue. |
--- |
2984 |
// or we got back a simplified value to continue. |
--- |
| 2985 |
std::optional SimplifiedPtrOp = |
--- |
2985 |
std::optional SimplifiedPtrOp = |
--- |
| 2986 |
stopOnUndefOrAssumed(A, PtrOp, &I); |
0 |
2986 |
stopOnUndefOrAssumed(A, PtrOp, &I); |
0 |
| 2987 |
if (!SimplifiedPtrOp || !*SimplifiedPtrOp) |
0 |
2987 |
if (!SimplifiedPtrOp || !*SimplifiedPtrOp) |
0 |
| 2988 |
return true; |
0 |
2988 |
return true; |
0 |
| 2989 |
const Value *PtrOpVal = *SimplifiedPtrOp; |
0 |
2989 |
const Value *PtrOpVal = *SimplifiedPtrOp; |
0 |
| 2990 |
|
--- |
2990 |
|
--- |
| 2991 |
// A memory access through a pointer is considered UB |
--- |
2991 |
// A memory access through a pointer is considered UB |
--- |
| 2992 |
// only if the pointer has constant null value. |
--- |
2992 |
// only if the pointer has constant null value. |
--- |
| 2993 |
// TODO: Expand it to not only check constant values. |
--- |
2993 |
// TODO: Expand it to not only check constant values. |
--- |
| 2994 |
if (!isa(PtrOpVal)) { |
0 |
2994 |
if (!isa(PtrOpVal)) { |
0 |
| 2995 |
AssumedNoUBInsts.insert(&I); |
0 |
2995 |
AssumedNoUBInsts.insert(&I); |
0 |
| 2996 |
return true; |
0 |
2996 |
return true; |
0 |
| 2997 |
} |
--- |
2997 |
} |
--- |
| 2998 |
const Type *PtrTy = PtrOpVal->getType(); |
0 |
2998 |
const Type *PtrTy = PtrOpVal->getType(); |
0 |
| 2999 |
|
--- |
2999 |
|
--- |
| 3000 |
// Because we only consider instructions inside functions, |
--- |
3000 |
// Because we only consider instructions inside functions, |
--- |
| 3001 |
// assume that a parent function exists. |
--- |
3001 |
// assume that a parent function exists. |
--- |
| 3002 |
const Function *F = I.getFunction(); |
0 |
3002 |
const Function *F = I.getFunction(); |
0 |
| 3003 |
|
--- |
3003 |
|
--- |
| 3004 |
// A memory access using constant null pointer is only considered UB |
--- |
3004 |
// A memory access using constant null pointer is only considered UB |
--- |
| 3005 |
// if null pointer is _not_ defined for the target platform. |
--- |
3005 |
// if null pointer is _not_ defined for the target platform. |
--- |
| 3006 |
if (llvm::NullPointerIsDefined(F, PtrTy->getPointerAddressSpace())) |
0 |
3006 |
if (llvm::NullPointerIsDefined(F, PtrTy->getPointerAddressSpace())) |
0 |
| 3007 |
AssumedNoUBInsts.insert(&I); |
0 |
3007 |
AssumedNoUBInsts.insert(&I); |
0 |
| 3008 |
else |
--- |
3008 |
else |
--- |
| 3009 |
KnownUBInsts.insert(&I); |
0 |
3009 |
KnownUBInsts.insert(&I); |
0 |
| 3010 |
return true; |
0 |
3010 |
return true; |
0 |
| 3011 |
}; |
0 |
3011 |
}; |
0 |
| 3012 |
|
--- |
3012 |
|
--- |
| 3013 |
auto InspectBrInstForUB = [&](Instruction &I) { |
0 |
3013 |
auto InspectBrInstForUB = [&](Instruction &I) { |
0 |
| 3014 |
// A conditional branch instruction is considered UB if it has `undef` |
--- |
3014 |
// A conditional branch instruction is considered UB if it has `undef` |
--- |
| 3015 |
// condition. |
--- |
3015 |
// condition. |
--- |
| 3016 |
|
--- |
3016 |
|
--- |
| 3017 |
// Skip instructions that are already saved. |
--- |
3017 |
// Skip instructions that are already saved. |
--- |
| 3018 |
if (AssumedNoUBInsts.count(&I) || KnownUBInsts.count(&I)) |
0 |
3018 |
if (AssumedNoUBInsts.count(&I) || KnownUBInsts.count(&I)) |
0 |
| 3019 |
return true; |
0 |
3019 |
return true; |
0 |
| 3020 |
|
--- |
3020 |
|
--- |
| 3021 |
// We know we have a branch instruction. |
--- |
3021 |
// We know we have a branch instruction. |
--- |
| 3022 |
auto *BrInst = cast(&I); |
0 |
3022 |
auto *BrInst = cast(&I); |
0 |
| 3023 |
|
--- |
3023 |
|
--- |
| 3024 |
// Unconditional branches are never considered UB. |
--- |
3024 |
// Unconditional branches are never considered UB. |
--- |
| 3025 |
if (BrInst->isUnconditional()) |
0 |
3025 |
if (BrInst->isUnconditional()) |
0 |
| 3026 |
return true; |
0 |
3026 |
return true; |
0 |
| 3027 |
|
--- |
3027 |
|
--- |
| 3028 |
// Either we stopped and the appropriate action was taken, |
--- |
3028 |
// Either we stopped and the appropriate action was taken, |
--- |
| 3029 |
// or we got back a simplified value to continue. |
--- |
3029 |
// or we got back a simplified value to continue. |
--- |
| 3030 |
std::optional SimplifiedCond = |
--- |
3030 |
std::optional SimplifiedCond = |
--- |
| 3031 |
stopOnUndefOrAssumed(A, BrInst->getCondition(), BrInst); |
0 |
3031 |
stopOnUndefOrAssumed(A, BrInst->getCondition(), BrInst); |
0 |
| 3032 |
if (!SimplifiedCond || !*SimplifiedCond) |
0 |
3032 |
if (!SimplifiedCond || !*SimplifiedCond) |
0 |
| 3033 |
return true; |
0 |
3033 |
return true; |
0 |
| 3034 |
AssumedNoUBInsts.insert(&I); |
0 |
3034 |
AssumedNoUBInsts.insert(&I); |
0 |
| 3035 |
return true; |
0 |
3035 |
return true; |
0 |
| 3036 |
}; |
0 |
3036 |
}; |
0 |
| 3037 |
|
--- |
3037 |
|
--- |
| 3038 |
auto InspectCallSiteForUB = [&](Instruction &I) { |
0 |
3038 |
auto InspectCallSiteForUB = [&](Instruction &I) { |
0 |
| 3039 |
// Check whether a callsite always cause UB or not |
--- |
3039 |
// Check whether a callsite always cause UB or not |
--- |
| 3040 |
|
--- |
3040 |
|
--- |
| 3041 |
// Skip instructions that are already saved. |
--- |
3041 |
// Skip instructions that are already saved. |
--- |
| 3042 |
if (AssumedNoUBInsts.count(&I) || KnownUBInsts.count(&I)) |
0 |
3042 |
if (AssumedNoUBInsts.count(&I) || KnownUBInsts.count(&I)) |
0 |
| 3043 |
return true; |
0 |
3043 |
return true; |
0 |
| 3044 |
|
--- |
3044 |
|
--- |
| 3045 |
// Check nonnull and noundef argument attribute violation for each |
--- |
3045 |
// Check nonnull and noundef argument attribute violation for each |
--- |
| 3046 |
// callsite. |
--- |
3046 |
// callsite. |
--- |
| 3047 |
CallBase &CB = cast(I); |
0 |
3047 |
CallBase &CB = cast(I); |
0 |
| 3048 |
auto *Callee = dyn_cast_if_present(CB.getCalledOperand()); |
0 |
3048 |
auto *Callee = dyn_cast_if_present(CB.getCalledOperand()); |
0 |
| 3049 |
if (!Callee) |
0 |
3049 |
if (!Callee) |
0 |
| 3050 |
return true; |
0 |
3050 |
return true; |
0 |
| 3051 |
for (unsigned idx = 0; idx < CB.arg_size(); idx++) { |
0 |
3051 |
for (unsigned idx = 0; idx < CB.arg_size(); idx++) { |
0 |
| 3052 |
// If current argument is known to be simplified to null pointer and the |
--- |
3052 |
// If current argument is known to be simplified to null pointer and the |
--- |
| 3053 |
// corresponding argument position is known to have nonnull attribute, |
--- |
3053 |
// corresponding argument position is known to have nonnull attribute, |
--- |
| 3054 |
// the argument is poison. Furthermore, if the argument is poison and |
--- |
3054 |
// the argument is poison. Furthermore, if the argument is poison and |
--- |
| 3055 |
// the position is known to have noundef attriubte, this callsite is |
--- |
3055 |
// the position is known to have noundef attriubte, this callsite is |
--- |
| 3056 |
// considered UB. |
--- |
3056 |
// considered UB. |
--- |
| 3057 |
if (idx >= Callee->arg_size()) |
0 |
3057 |
if (idx >= Callee->arg_size()) |
0 |
| 3058 |
break; |
0 |
3058 |
break; |
0 |
| 3059 |
Value *ArgVal = CB.getArgOperand(idx); |
0 |
3059 |
Value *ArgVal = CB.getArgOperand(idx); |
0 |
| 3060 |
if (!ArgVal) |
0 |
3060 |
if (!ArgVal) |
0 |
| 3061 |
continue; |
0 |
3061 |
continue; |
0 |
| 3062 |
// Here, we handle three cases. |
--- |
3062 |
// Here, we handle three cases. |
--- |
| 3063 |
// (1) Not having a value means it is dead. (we can replace the value |
--- |
3063 |
// (1) Not having a value means it is dead. (we can replace the value |
--- |
| 3064 |
// with undef) |
--- |
3064 |
// with undef) |
--- |
| 3065 |
// (2) Simplified to undef. The argument violate noundef attriubte. |
--- |
3065 |
// (2) Simplified to undef. The argument violate noundef attriubte. |
--- |
| 3066 |
// (3) Simplified to null pointer where known to be nonnull. |
--- |
3066 |
// (3) Simplified to null pointer where known to be nonnull. |
--- |
| 3067 |
// The argument is a poison value and violate noundef attribute. |
--- |
3067 |
// The argument is a poison value and violate noundef attribute. |
--- |
| 3068 |
IRPosition CalleeArgumentIRP = IRPosition::callsite_argument(CB, idx); |
0 |
3068 |
IRPosition CalleeArgumentIRP = IRPosition::callsite_argument(CB, idx); |
0 |
| 3069 |
bool IsKnownNoUndef; |
--- |
3069 |
bool IsKnownNoUndef; |
--- |
| 3070 |
AA::hasAssumedIRAttr( |
0 |
3070 |
AA::hasAssumedIRAttr( |
0 |
| 3071 |
A, this, CalleeArgumentIRP, DepClassTy::NONE, IsKnownNoUndef); |
0 |
3071 |
A, this, CalleeArgumentIRP, DepClassTy::NONE, IsKnownNoUndef); |
0 |
| 3072 |
if (!IsKnownNoUndef) |
0 |
3072 |
if (!IsKnownNoUndef) |
0 |
| 3073 |
continue; |
0 |
3073 |
continue; |
0 |
| 3074 |
bool UsedAssumedInformation = false; |
0 |
3074 |
bool UsedAssumedInformation = false; |
0 |
| 3075 |
std::optional SimplifiedVal = |
--- |
3075 |
std::optional SimplifiedVal = |
--- |
| 3076 |
A.getAssumedSimplified(IRPosition::value(*ArgVal), *this, |
0 |
3076 |
A.getAssumedSimplified(IRPosition::value(*ArgVal), *this, |
0 |
| 3077 |
UsedAssumedInformation, AA::Interprocedural); |
--- |
3077 |
UsedAssumedInformation, AA::Interprocedural); |
--- |
| 3078 |
if (UsedAssumedInformation) |
0 |
3078 |
if (UsedAssumedInformation) |
0 |
| 3079 |
continue; |
0 |
3079 |
continue; |
0 |
| 3080 |
if (SimplifiedVal && !*SimplifiedVal) |
0 |
3080 |
if (SimplifiedVal && !*SimplifiedVal) |
0 |
| 3081 |
return true; |
0 |
3081 |
return true; |
0 |
| 3082 |
if (!SimplifiedVal || isa(**SimplifiedVal)) { |
0 |
3082 |
if (!SimplifiedVal || isa(**SimplifiedVal)) { |
0 |
| 3083 |
KnownUBInsts.insert(&I); |
0 |
3083 |
KnownUBInsts.insert(&I); |
0 |
| 3084 |
continue; |
0 |
3084 |
continue; |
0 |
| 3085 |
} |
--- |
3085 |
} |
--- |
| 3086 |
if (!ArgVal->getType()->isPointerTy() || |
0 |
3086 |
if (!ArgVal->getType()->isPointerTy() || |
0 |
| 3087 |
!isa(**SimplifiedVal)) |
0 |
3087 |
!isa(**SimplifiedVal)) |
0 |
| 3088 |
continue; |
0 |
3088 |
continue; |
0 |
| 3089 |
bool IsKnownNonNull; |
--- |
3089 |
bool IsKnownNonNull; |
--- |
| 3090 |
AA::hasAssumedIRAttr( |
0 |
3090 |
AA::hasAssumedIRAttr( |
0 |
| 3091 |
A, this, CalleeArgumentIRP, DepClassTy::NONE, IsKnownNonNull); |
--- |
3091 |
A, this, CalleeArgumentIRP, DepClassTy::NONE, IsKnownNonNull); |
--- |
| 3092 |
if (IsKnownNonNull) |
0 |
3092 |
if (IsKnownNonNull) |
0 |
| 3093 |
KnownUBInsts.insert(&I); |
0 |
3093 |
KnownUBInsts.insert(&I); |
0 |
| 3094 |
} |
--- |
3094 |
} |
--- |
| 3095 |
return true; |
0 |
3095 |
return true; |
0 |
| 3096 |
}; |
0 |
3096 |
}; |
0 |
| 3097 |
|
--- |
3097 |
|
--- |
| 3098 |
auto InspectReturnInstForUB = [&](Instruction &I) { |
0 |
3098 |
auto InspectReturnInstForUB = [&](Instruction &I) { |
0 |
| 3099 |
auto &RI = cast(I); |
0 |
3099 |
auto &RI = cast(I); |
0 |
| 3100 |
// Either we stopped and the appropriate action was taken, |
--- |
3100 |
// Either we stopped and the appropriate action was taken, |
--- |
| 3101 |
// or we got back a simplified return value to continue. |
--- |
3101 |
// or we got back a simplified return value to continue. |
--- |
| 3102 |
std::optional SimplifiedRetValue = |
--- |
3102 |
std::optional SimplifiedRetValue = |
--- |
| 3103 |
stopOnUndefOrAssumed(A, RI.getReturnValue(), &I); |
0 |
3103 |
stopOnUndefOrAssumed(A, RI.getReturnValue(), &I); |
0 |
| 3104 |
if (!SimplifiedRetValue || !*SimplifiedRetValue) |
0 |
3104 |
if (!SimplifiedRetValue || !*SimplifiedRetValue) |
0 |
| 3105 |
return true; |
0 |
3105 |
return true; |
0 |
| 3106 |
|
--- |
3106 |
|
--- |
| 3107 |
// Check if a return instruction always cause UB or not |
--- |
3107 |
// Check if a return instruction always cause UB or not |
--- |
| 3108 |
// Note: It is guaranteed that the returned position of the anchor |
--- |
3108 |
// Note: It is guaranteed that the returned position of the anchor |
--- |
| 3109 |
// scope has noundef attribute when this is called. |
--- |
3109 |
// scope has noundef attribute when this is called. |
--- |
| 3110 |
// We also ensure the return position is not "assumed dead" |
--- |
3110 |
// We also ensure the return position is not "assumed dead" |
--- |
| 3111 |
// because the returned value was then potentially simplified to |
--- |
3111 |
// because the returned value was then potentially simplified to |
--- |
| 3112 |
// `undef` in AAReturnedValues without removing the `noundef` |
--- |
3112 |
// `undef` in AAReturnedValues without removing the `noundef` |
--- |
| 3113 |
// attribute yet. |
--- |
3113 |
// attribute yet. |
--- |
| 3114 |
|
--- |
3114 |
|
--- |
| 3115 |
// When the returned position has noundef attriubte, UB occurs in the |
--- |
3115 |
// When the returned position has noundef attriubte, UB occurs in the |
--- |
| 3116 |
// following cases. |
--- |
3116 |
// following cases. |
--- |
| 3117 |
// (1) Returned value is known to be undef. |
--- |
3117 |
// (1) Returned value is known to be undef. |
--- |
| 3118 |
// (2) The value is known to be a null pointer and the returned |
--- |
3118 |
// (2) The value is known to be a null pointer and the returned |
--- |
| 3119 |
// position has nonnull attribute (because the returned value is |
--- |
3119 |
// position has nonnull attribute (because the returned value is |
--- |
| 3120 |
// poison). |
--- |
3120 |
// poison). |
--- |
| 3121 |
if (isa(*SimplifiedRetValue)) { |
0 |
3121 |
if (isa(*SimplifiedRetValue)) { |
0 |
| 3122 |
bool IsKnownNonNull; |
--- |
3122 |
bool IsKnownNonNull; |
--- |
| 3123 |
AA::hasAssumedIRAttr( |
0 |
3123 |
AA::hasAssumedIRAttr( |
0 |
| 3124 |
A, this, IRPosition::returned(*getAnchorScope()), DepClassTy::NONE, |
0 |
3124 |
A, this, IRPosition::returned(*getAnchorScope()), DepClassTy::NONE, |
0 |
| 3125 |
IsKnownNonNull); |
--- |
3125 |
IsKnownNonNull); |
--- |
| 3126 |
if (IsKnownNonNull) |
0 |
3126 |
if (IsKnownNonNull) |
0 |
| 3127 |
KnownUBInsts.insert(&I); |
0 |
3127 |
KnownUBInsts.insert(&I); |
0 |
| 3128 |
} |
--- |
3128 |
} |
--- |
| 3129 |
|
--- |
3129 |
|
--- |
| 3130 |
return true; |
0 |
3130 |
return true; |
0 |
| 3131 |
}; |
0 |
3131 |
}; |
0 |
| 3132 |
|
--- |
3132 |
|
--- |
| 3133 |
bool UsedAssumedInformation = false; |
0 |
3133 |
bool UsedAssumedInformation = false; |
0 |
| 3134 |
A.checkForAllInstructions(InspectMemAccessInstForUB, *this, |
0 |
3134 |
A.checkForAllInstructions(InspectMemAccessInstForUB, *this, |
0 |
| 3135 |
{Instruction::Load, Instruction::Store, |
--- |
3135 |
{Instruction::Load, Instruction::Store, |
--- |
| 3136 |
Instruction::AtomicCmpXchg, |
--- |
3136 |
Instruction::AtomicCmpXchg, |
--- |
| 3137 |
Instruction::AtomicRMW}, |
--- |
3137 |
Instruction::AtomicRMW}, |
--- |
| 3138 |
UsedAssumedInformation, |
--- |
3138 |
UsedAssumedInformation, |
--- |
| 3139 |
/* CheckBBLivenessOnly */ true); |
--- |
3139 |
/* CheckBBLivenessOnly */ true); |
--- |
| 3140 |
A.checkForAllInstructions(InspectBrInstForUB, *this, {Instruction::Br}, |
0 |
3140 |
A.checkForAllInstructions(InspectBrInstForUB, *this, {Instruction::Br}, |
0 |
| 3141 |
UsedAssumedInformation, |
--- |
3141 |
UsedAssumedInformation, |
--- |
| 3142 |
/* CheckBBLivenessOnly */ true); |
--- |
3142 |
/* CheckBBLivenessOnly */ true); |
--- |
| 3143 |
A.checkForAllCallLikeInstructions(InspectCallSiteForUB, *this, |
0 |
3143 |
A.checkForAllCallLikeInstructions(InspectCallSiteForUB, *this, |
0 |
| 3144 |
UsedAssumedInformation); |
--- |
3144 |
UsedAssumedInformation); |
--- |
| 3145 |
|
--- |
3145 |
|
--- |
| 3146 |
// If the returned position of the anchor scope has noundef attriubte, check |
--- |
3146 |
// If the returned position of the anchor scope has noundef attriubte, check |
--- |
| 3147 |
// all returned instructions. |
--- |
3147 |
// all returned instructions. |
--- |
| 3148 |
if (!getAnchorScope()->getReturnType()->isVoidTy()) { |
0 |
3148 |
if (!getAnchorScope()->getReturnType()->isVoidTy()) { |
0 |
| 3149 |
const IRPosition &ReturnIRP = IRPosition::returned(*getAnchorScope()); |
0 |
3149 |
const IRPosition &ReturnIRP = IRPosition::returned(*getAnchorScope()); |
0 |
| 3150 |
if (!A.isAssumedDead(ReturnIRP, this, nullptr, UsedAssumedInformation)) { |
0 |
3150 |
if (!A.isAssumedDead(ReturnIRP, this, nullptr, UsedAssumedInformation)) { |
0 |
| 3151 |
bool IsKnownNoUndef; |
--- |
3151 |
bool IsKnownNoUndef; |
--- |
| 3152 |
AA::hasAssumedIRAttr( |
0 |
3152 |
AA::hasAssumedIRAttr( |
0 |
| 3153 |
A, this, ReturnIRP, DepClassTy::NONE, IsKnownNoUndef); |
--- |
3153 |
A, this, ReturnIRP, DepClassTy::NONE, IsKnownNoUndef); |
--- |
| 3154 |
if (IsKnownNoUndef) |
0 |
3154 |
if (IsKnownNoUndef) |
0 |
| 3155 |
A.checkForAllInstructions(InspectReturnInstForUB, *this, |
0 |
3155 |
A.checkForAllInstructions(InspectReturnInstForUB, *this, |
0 |
| 3156 |
{Instruction::Ret}, UsedAssumedInformation, |
--- |
3156 |
{Instruction::Ret}, UsedAssumedInformation, |
--- |
| 3157 |
/* CheckBBLivenessOnly */ true); |
--- |
3157 |
/* CheckBBLivenessOnly */ true); |
--- |
| 3158 |
} |
--- |
3158 |
} |
--- |
| 3159 |
} |
--- |
3159 |
} |
--- |
| 3160 |
|
--- |
3160 |
|
--- |
| 3161 |
if (NoUBPrevSize != AssumedNoUBInsts.size() || |
0 |
3161 |
if (NoUBPrevSize != AssumedNoUBInsts.size() || |
0 |
| 3162 |
UBPrevSize != KnownUBInsts.size()) |
0 |
3162 |
UBPrevSize != KnownUBInsts.size()) |
0 |
| 3163 |
return ChangeStatus::CHANGED; |
0 |
3163 |
return ChangeStatus::CHANGED; |
0 |
| 3164 |
return ChangeStatus::UNCHANGED; |
0 |
3164 |
return ChangeStatus::UNCHANGED; |
0 |
| 3165 |
} |
--- |
3165 |
} |
--- |
| 3166 |
|
--- |
3166 |
|
--- |
| 3167 |
bool isKnownToCauseUB(Instruction *I) const override { |
0 |
3167 |
bool isKnownToCauseUB(Instruction *I) const override { |
0 |
| 3168 |
return KnownUBInsts.count(I); |
0 |
3168 |
return KnownUBInsts.count(I); |
0 |
| 3169 |
} |
--- |
3169 |
} |
--- |
| 3170 |
|
--- |
3170 |
|
--- |
| 3171 |
bool isAssumedToCauseUB(Instruction *I) const override { |
0 |
3171 |
bool isAssumedToCauseUB(Instruction *I) const override { |
0 |
| 3172 |
// In simple words, if an instruction is not in the assumed to _not_ |
--- |
3172 |
// In simple words, if an instruction is not in the assumed to _not_ |
--- |
| 3173 |
// cause UB, then it is assumed UB (that includes those |
--- |
3173 |
// cause UB, then it is assumed UB (that includes those |
--- |
| 3174 |
// in the KnownUBInsts set). The rest is boilerplate |
--- |
3174 |
// in the KnownUBInsts set). The rest is boilerplate |
--- |
| 3175 |
// is to ensure that it is one of the instructions we test |
--- |
3175 |
// is to ensure that it is one of the instructions we test |
--- |
| 3176 |
// for UB. |
--- |
3176 |
// for UB. |
--- |
| 3177 |
|
--- |
3177 |
|
--- |
| 3178 |
switch (I->getOpcode()) { |
0 |
3178 |
switch (I->getOpcode()) { |
0 |
| 3179 |
case Instruction::Load: |
0 |
3179 |
case Instruction::Load: |
0 |
| 3180 |
case Instruction::Store: |
--- |
3180 |
case Instruction::Store: |
--- |
| 3181 |
case Instruction::AtomicCmpXchg: |
--- |
3181 |
case Instruction::AtomicCmpXchg: |
--- |
| 3182 |
case Instruction::AtomicRMW: |
--- |
3182 |
case Instruction::AtomicRMW: |
--- |
| 3183 |
return !AssumedNoUBInsts.count(I); |
0 |
3183 |
return !AssumedNoUBInsts.count(I); |
0 |
| 3184 |
case Instruction::Br: { |
0 |
3184 |
case Instruction::Br: { |
0 |
| 3185 |
auto *BrInst = cast(I); |
0 |
3185 |
auto *BrInst = cast(I); |
0 |
| 3186 |
if (BrInst->isUnconditional()) |
0 |
3186 |
if (BrInst->isUnconditional()) |
0 |
| 3187 |
return false; |
0 |
3187 |
return false; |
0 |
| 3188 |
return !AssumedNoUBInsts.count(I); |
0 |
3188 |
return !AssumedNoUBInsts.count(I); |
0 |
| 3189 |
} break; |
--- |
3189 |
} break; |
--- |
| 3190 |
default: |
0 |
3190 |
default: |
0 |
| 3191 |
return false; |
0 |
3191 |
return false; |
0 |
| 3192 |
} |
--- |
3192 |
} |
--- |
| 3193 |
return false; |
--- |
3193 |
return false; |
--- |
| 3194 |
} |
--- |
3194 |
} |
--- |
| 3195 |
|
--- |
3195 |
|
--- |
| 3196 |
ChangeStatus manifest(Attributor &A) override { |
0 |
3196 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 3197 |
if (KnownUBInsts.empty()) |
0 |
3197 |
if (KnownUBInsts.empty()) |
0 |
| 3198 |
return ChangeStatus::UNCHANGED; |
0 |
3198 |
return ChangeStatus::UNCHANGED; |
0 |
| 3199 |
for (Instruction *I : KnownUBInsts) |
0 |
3199 |
for (Instruction *I : KnownUBInsts) |
0 |
| 3200 |
A.changeToUnreachableAfterManifest(I); |
0 |
3200 |
A.changeToUnreachableAfterManifest(I); |
0 |
| 3201 |
return ChangeStatus::CHANGED; |
0 |
3201 |
return ChangeStatus::CHANGED; |
0 |
| 3202 |
} |
--- |
3202 |
} |
--- |
| 3203 |
|
--- |
3203 |
|
--- |
| 3204 |
/// See AbstractAttribute::getAsStr() |
--- |
3204 |
/// See AbstractAttribute::getAsStr() |
--- |
| 3205 |
const std::string getAsStr(Attributor *A) const override { |
0 |
3205 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 3206 |
return getAssumed() ? "undefined-behavior" : "no-ub"; |
0 |
3206 |
return getAssumed() ? "undefined-behavior" : "no-ub"; |
0 |
| 3207 |
} |
--- |
3207 |
} |
--- |
| 3208 |
|
--- |
3208 |
|
--- |
| 3209 |
/// Note: The correctness of this analysis depends on the fact that the |
--- |
3209 |
/// Note: The correctness of this analysis depends on the fact that the |
--- |
| 3210 |
/// following 2 sets will stop changing after some point. |
--- |
3210 |
/// following 2 sets will stop changing after some point. |
--- |
| 3211 |
/// "Change" here means that their size changes. |
--- |
3211 |
/// "Change" here means that their size changes. |
--- |
| 3212 |
/// The size of each set is monotonically increasing |
--- |
3212 |
/// The size of each set is monotonically increasing |
--- |
| 3213 |
/// (we only add items to them) and it is upper bounded by the number of |
--- |
3213 |
/// (we only add items to them) and it is upper bounded by the number of |
--- |
| 3214 |
/// instructions in the processed function (we can never save more |
--- |
3214 |
/// instructions in the processed function (we can never save more |
--- |
| 3215 |
/// elements in either set than this number). Hence, at some point, |
--- |
3215 |
/// elements in either set than this number). Hence, at some point, |
--- |
| 3216 |
/// they will stop increasing. |
--- |
3216 |
/// they will stop increasing. |
--- |
| 3217 |
/// Consequently, at some point, both sets will have stopped |
--- |
3217 |
/// Consequently, at some point, both sets will have stopped |
--- |
| 3218 |
/// changing, effectively making the analysis reach a fixpoint. |
--- |
3218 |
/// changing, effectively making the analysis reach a fixpoint. |
--- |
| 3219 |
|
--- |
3219 |
|
--- |
| 3220 |
/// Note: These 2 sets are disjoint and an instruction can be considered |
--- |
3220 |
/// Note: These 2 sets are disjoint and an instruction can be considered |
--- |
| 3221 |
/// one of 3 things: |
--- |
3221 |
/// one of 3 things: |
--- |
| 3222 |
/// 1) Known to cause UB (AAUndefinedBehavior could prove it) and put it in |
--- |
3222 |
/// 1) Known to cause UB (AAUndefinedBehavior could prove it) and put it in |
--- |
| 3223 |
/// the KnownUBInsts set. |
--- |
3223 |
/// the KnownUBInsts set. |
--- |
| 3224 |
/// 2) Assumed to cause UB (in every updateImpl, AAUndefinedBehavior |
--- |
3224 |
/// 2) Assumed to cause UB (in every updateImpl, AAUndefinedBehavior |
--- |
| 3225 |
/// has a reason to assume it). |
--- |
3225 |
/// has a reason to assume it). |
--- |
| 3226 |
/// 3) Assumed to not cause UB. very other instruction - AAUndefinedBehavior |
--- |
3226 |
/// 3) Assumed to not cause UB. very other instruction - AAUndefinedBehavior |
--- |
| 3227 |
/// could not find a reason to assume or prove that it can cause UB, |
--- |
3227 |
/// could not find a reason to assume or prove that it can cause UB, |
--- |
| 3228 |
/// hence it assumes it doesn't. We have a set for these instructions |
--- |
3228 |
/// hence it assumes it doesn't. We have a set for these instructions |
--- |
| 3229 |
/// so that we don't reprocess them in every update. |
--- |
3229 |
/// so that we don't reprocess them in every update. |
--- |
| 3230 |
/// Note however that instructions in this set may cause UB. |
--- |
3230 |
/// Note however that instructions in this set may cause UB. |
--- |
| 3231 |
|
--- |
3231 |
|
--- |
| 3232 |
protected: |
--- |
3232 |
protected: |
--- |
| 3233 |
/// A set of all live instructions _known_ to cause UB. |
--- |
3233 |
/// A set of all live instructions _known_ to cause UB. |
--- |
| 3234 |
SmallPtrSet KnownUBInsts; |
--- |
3234 |
SmallPtrSet KnownUBInsts; |
--- |
| 3235 |
|
--- |
3235 |
|
--- |
| 3236 |
private: |
--- |
3236 |
private: |
--- |
| 3237 |
/// A set of all the (live) instructions that are assumed to _not_ cause UB. |
--- |
3237 |
/// A set of all the (live) instructions that are assumed to _not_ cause UB. |
--- |
| 3238 |
SmallPtrSet AssumedNoUBInsts; |
--- |
3238 |
SmallPtrSet AssumedNoUBInsts; |
--- |
| 3239 |
|
--- |
3239 |
|
--- |
| 3240 |
// Should be called on updates in which if we're processing an instruction |
--- |
3240 |
// Should be called on updates in which if we're processing an instruction |
--- |
| 3241 |
// \p I that depends on a value \p V, one of the following has to happen: |
--- |
3241 |
// \p I that depends on a value \p V, one of the following has to happen: |
--- |
| 3242 |
// - If the value is assumed, then stop. |
--- |
3242 |
// - If the value is assumed, then stop. |
--- |
| 3243 |
// - If the value is known but undef, then consider it UB. |
--- |
3243 |
// - If the value is known but undef, then consider it UB. |
--- |
| 3244 |
// - Otherwise, do specific processing with the simplified value. |
--- |
3244 |
// - Otherwise, do specific processing with the simplified value. |
--- |
| 3245 |
// We return std::nullopt in the first 2 cases to signify that an appropriate |
--- |
3245 |
// We return std::nullopt in the first 2 cases to signify that an appropriate |
--- |
| 3246 |
// action was taken and the caller should stop. |
--- |
3246 |
// action was taken and the caller should stop. |
--- |
| 3247 |
// Otherwise, we return the simplified value that the caller should |
--- |
3247 |
// Otherwise, we return the simplified value that the caller should |
--- |
| 3248 |
// use for specific processing. |
--- |
3248 |
// use for specific processing. |
--- |
| 3249 |
std::optional stopOnUndefOrAssumed(Attributor &A, Value *V, |
0 |
3249 |
std::optional stopOnUndefOrAssumed(Attributor &A, Value *V, |
0 |
| 3250 |
Instruction *I) { |
--- |
3250 |
Instruction *I) { |
--- |
| 3251 |
bool UsedAssumedInformation = false; |
0 |
3251 |
bool UsedAssumedInformation = false; |
0 |
| 3252 |
std::optional SimplifiedV = |
--- |
3252 |
std::optional SimplifiedV = |
--- |
| 3253 |
A.getAssumedSimplified(IRPosition::value(*V), *this, |
0 |
3253 |
A.getAssumedSimplified(IRPosition::value(*V), *this, |
0 |
| 3254 |
UsedAssumedInformation, AA::Interprocedural); |
--- |
3254 |
UsedAssumedInformation, AA::Interprocedural); |
--- |
| 3255 |
if (!UsedAssumedInformation) { |
0 |
3255 |
if (!UsedAssumedInformation) { |
0 |
| 3256 |
// Don't depend on assumed values. |
--- |
3256 |
// Don't depend on assumed values. |
--- |
| 3257 |
if (!SimplifiedV) { |
0 |
3257 |
if (!SimplifiedV) { |
0 |
| 3258 |
// If it is known (which we tested above) but it doesn't have a value, |
--- |
3258 |
// If it is known (which we tested above) but it doesn't have a value, |
--- |
| 3259 |
// then we can assume `undef` and hence the instruction is UB. |
--- |
3259 |
// then we can assume `undef` and hence the instruction is UB. |
--- |
| 3260 |
KnownUBInsts.insert(I); |
0 |
3260 |
KnownUBInsts.insert(I); |
0 |
| 3261 |
return std::nullopt; |
0 |
3261 |
return std::nullopt; |
0 |
| 3262 |
} |
--- |
3262 |
} |
--- |
| 3263 |
if (!*SimplifiedV) |
0 |
3263 |
if (!*SimplifiedV) |
0 |
| 3264 |
return nullptr; |
0 |
3264 |
return nullptr; |
0 |
| 3265 |
V = *SimplifiedV; |
0 |
3265 |
V = *SimplifiedV; |
0 |
| 3266 |
} |
--- |
3266 |
} |
--- |
| 3267 |
if (isa(V)) { |
0 |
3267 |
if (isa(V)) { |
0 |
| 3268 |
KnownUBInsts.insert(I); |
0 |
3268 |
KnownUBInsts.insert(I); |
0 |
| 3269 |
return std::nullopt; |
0 |
3269 |
return std::nullopt; |
0 |
| 3270 |
} |
--- |
3270 |
} |
--- |
| 3271 |
return V; |
0 |
3271 |
return V; |
0 |
| 3272 |
} |
--- |
3272 |
} |
--- |
| 3273 |
}; |
--- |
3273 |
}; |
--- |
| 3274 |
|
--- |
3274 |
|
--- |
| 3275 |
struct AAUndefinedBehaviorFunction final : AAUndefinedBehaviorImpl { |
--- |
3275 |
struct AAUndefinedBehaviorFunction final : AAUndefinedBehaviorImpl { |
--- |
| 3276 |
AAUndefinedBehaviorFunction(const IRPosition &IRP, Attributor &A) |
0 |
3276 |
AAUndefinedBehaviorFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 3277 |
: AAUndefinedBehaviorImpl(IRP, A) {} |
0 |
3277 |
: AAUndefinedBehaviorImpl(IRP, A) {} |
0 |
| 3278 |
|
--- |
3278 |
|
--- |
| 3279 |
/// See AbstractAttribute::trackStatistics() |
--- |
3279 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 3280 |
void trackStatistics() const override { |
0 |
3280 |
void trackStatistics() const override { |
0 |
| 3281 |
STATS_DECL(UndefinedBehaviorInstruction, Instruction, |
--- |
3281 |
STATS_DECL(UndefinedBehaviorInstruction, Instruction, |
--- |
| 3282 |
"Number of instructions known to have UB"); |
--- |
3282 |
"Number of instructions known to have UB"); |
--- |
| 3283 |
BUILD_STAT_NAME(UndefinedBehaviorInstruction, Instruction) += |
--- |
3283 |
BUILD_STAT_NAME(UndefinedBehaviorInstruction, Instruction) += |
--- |
| 3284 |
KnownUBInsts.size(); |
0 |
3284 |
KnownUBInsts.size(); |
0 |
| 3285 |
} |
0 |
3285 |
} |
0 |
| 3286 |
}; |
--- |
3286 |
}; |
--- |
| 3287 |
} // namespace |
--- |
3287 |
} // namespace |
--- |
| 3288 |
|
--- |
3288 |
|
--- |
| 3289 |
/// ------------------------ Will-Return Attributes ---------------------------- |
--- |
3289 |
/// ------------------------ Will-Return Attributes ---------------------------- |
--- |
| 3290 |
|
--- |
3290 |
|
--- |
| 3291 |
namespace { |
--- |
3291 |
namespace { |
--- |
| 3292 |
// Helper function that checks whether a function has any cycle which we don't |
--- |
3292 |
// Helper function that checks whether a function has any cycle which we don't |
--- |
| 3293 |
// know if it is bounded or not. |
--- |
3293 |
// know if it is bounded or not. |
--- |
| 3294 |
// Loops with maximum trip count are considered bounded, any other cycle not. |
--- |
3294 |
// Loops with maximum trip count are considered bounded, any other cycle not. |
--- |
| 3295 |
static bool mayContainUnboundedCycle(Function &F, Attributor &A) { |
0 |
3295 |
static bool mayContainUnboundedCycle(Function &F, Attributor &A) { |
0 |
| 3296 |
ScalarEvolution *SE = |
--- |
3296 |
ScalarEvolution *SE = |
--- |
| 3297 |
A.getInfoCache().getAnalysisResultForFunction(F); |
0 |
3297 |
A.getInfoCache().getAnalysisResultForFunction(F); |
0 |
| 3298 |
LoopInfo *LI = A.getInfoCache().getAnalysisResultForFunction(F); |
0 |
3298 |
LoopInfo *LI = A.getInfoCache().getAnalysisResultForFunction(F); |
0 |
| 3299 |
// If either SCEV or LoopInfo is not available for the function then we assume |
--- |
3299 |
// If either SCEV or LoopInfo is not available for the function then we assume |
--- |
| 3300 |
// any cycle to be unbounded cycle. |
--- |
3300 |
// any cycle to be unbounded cycle. |
--- |
| 3301 |
// We use scc_iterator which uses Tarjan algorithm to find all the maximal |
--- |
3301 |
// We use scc_iterator which uses Tarjan algorithm to find all the maximal |
--- |
| 3302 |
// SCCs.To detect if there's a cycle, we only need to find the maximal ones. |
--- |
3302 |
// SCCs.To detect if there's a cycle, we only need to find the maximal ones. |
--- |
| 3303 |
if (!SE || !LI) { |
0 |
3303 |
if (!SE || !LI) { |
0 |
| 3304 |
for (scc_iterator SCCI = scc_begin(&F); !SCCI.isAtEnd(); ++SCCI) |
0 |
3304 |
for (scc_iterator SCCI = scc_begin(&F); !SCCI.isAtEnd(); ++SCCI) |
0 |
| 3305 |
if (SCCI.hasCycle()) |
0 |
3305 |
if (SCCI.hasCycle()) |
0 |
| 3306 |
return true; |
0 |
3306 |
return true; |
0 |
| 3307 |
return false; |
0 |
3307 |
return false; |
0 |
| 3308 |
} |
--- |
3308 |
} |
--- |
| 3309 |
|
--- |
3309 |
|
--- |
| 3310 |
// If there's irreducible control, the function may contain non-loop cycles. |
--- |
3310 |
// If there's irreducible control, the function may contain non-loop cycles. |
--- |
| 3311 |
if (mayContainIrreducibleControl(F, LI)) |
0 |
3311 |
if (mayContainIrreducibleControl(F, LI)) |
0 |
| 3312 |
return true; |
0 |
3312 |
return true; |
0 |
| 3313 |
|
--- |
3313 |
|
--- |
| 3314 |
// Any loop that does not have a max trip count is considered unbounded cycle. |
--- |
3314 |
// Any loop that does not have a max trip count is considered unbounded cycle. |
--- |
| 3315 |
for (auto *L : LI->getLoopsInPreorder()) { |
0 |
3315 |
for (auto *L : LI->getLoopsInPreorder()) { |
0 |
| 3316 |
if (!SE->getSmallConstantMaxTripCount(L)) |
0 |
3316 |
if (!SE->getSmallConstantMaxTripCount(L)) |
0 |
| 3317 |
return true; |
0 |
3317 |
return true; |
0 |
| 3318 |
} |
0 |
3318 |
} |
0 |
| 3319 |
return false; |
0 |
3319 |
return false; |
0 |
| 3320 |
} |
--- |
3320 |
} |
--- |
| 3321 |
|
--- |
3321 |
|
--- |
| 3322 |
struct AAWillReturnImpl : public AAWillReturn { |
--- |
3322 |
struct AAWillReturnImpl : public AAWillReturn { |
--- |
| 3323 |
AAWillReturnImpl(const IRPosition &IRP, Attributor &A) |
0 |
3323 |
AAWillReturnImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 3324 |
: AAWillReturn(IRP, A) {} |
0 |
3324 |
: AAWillReturn(IRP, A) {} |
0 |
| 3325 |
|
--- |
3325 |
|
--- |
| 3326 |
/// See AbstractAttribute::initialize(...). |
--- |
3326 |
/// See AbstractAttribute::initialize(...). |
--- |
| 3327 |
void initialize(Attributor &A) override { |
0 |
3327 |
void initialize(Attributor &A) override { |
0 |
| 3328 |
bool IsKnown; |
--- |
3328 |
bool IsKnown; |
--- |
| 3329 |
assert(!AA::hasAssumedIRAttr( |
0 |
3329 |
assert(!AA::hasAssumedIRAttr( |
0 |
| 3330 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
3330 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
| 3331 |
(void)IsKnown; |
--- |
3331 |
(void)IsKnown; |
--- |
| 3332 |
} |
0 |
3332 |
} |
0 |
| 3333 |
|
--- |
3333 |
|
--- |
| 3334 |
/// Check for `mustprogress` and `readonly` as they imply `willreturn`. |
--- |
3334 |
/// Check for `mustprogress` and `readonly` as they imply `willreturn`. |
--- |
| 3335 |
bool isImpliedByMustprogressAndReadonly(Attributor &A, bool KnownOnly) { |
0 |
3335 |
bool isImpliedByMustprogressAndReadonly(Attributor &A, bool KnownOnly) { |
0 |
| 3336 |
if (!A.hasAttr(getIRPosition(), {Attribute::MustProgress})) |
0 |
3336 |
if (!A.hasAttr(getIRPosition(), {Attribute::MustProgress})) |
0 |
| 3337 |
return false; |
0 |
3337 |
return false; |
0 |
| 3338 |
|
--- |
3338 |
|
--- |
| 3339 |
bool IsKnown; |
--- |
3339 |
bool IsKnown; |
--- |
| 3340 |
if (AA::isAssumedReadOnly(A, getIRPosition(), *this, IsKnown)) |
0 |
3340 |
if (AA::isAssumedReadOnly(A, getIRPosition(), *this, IsKnown)) |
0 |
| 3341 |
return IsKnown || !KnownOnly; |
0 |
3341 |
return IsKnown || !KnownOnly; |
0 |
| 3342 |
return false; |
0 |
3342 |
return false; |
0 |
| 3343 |
} |
--- |
3343 |
} |
--- |
| 3344 |
|
--- |
3344 |
|
--- |
| 3345 |
/// See AbstractAttribute::updateImpl(...). |
--- |
3345 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 3346 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
3346 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 3347 |
if (isImpliedByMustprogressAndReadonly(A, /* KnownOnly */ false)) |
0 |
3347 |
if (isImpliedByMustprogressAndReadonly(A, /* KnownOnly */ false)) |
0 |
| 3348 |
return ChangeStatus::UNCHANGED; |
0 |
3348 |
return ChangeStatus::UNCHANGED; |
0 |
| 3349 |
|
--- |
3349 |
|
--- |
| 3350 |
auto CheckForWillReturn = [&](Instruction &I) { |
0 |
3350 |
auto CheckForWillReturn = [&](Instruction &I) { |
0 |
| 3351 |
IRPosition IPos = IRPosition::callsite_function(cast(I)); |
0 |
3351 |
IRPosition IPos = IRPosition::callsite_function(cast(I)); |
0 |
| 3352 |
bool IsKnown; |
--- |
3352 |
bool IsKnown; |
--- |
| 3353 |
if (AA::hasAssumedIRAttr( |
0 |
3353 |
if (AA::hasAssumedIRAttr( |
0 |
| 3354 |
A, this, IPos, DepClassTy::REQUIRED, IsKnown)) { |
0 |
3354 |
A, this, IPos, DepClassTy::REQUIRED, IsKnown)) { |
0 |
| 3355 |
if (IsKnown) |
0 |
3355 |
if (IsKnown) |
0 |
| 3356 |
return true; |
0 |
3356 |
return true; |
0 |
| 3357 |
} else { |
--- |
3357 |
} else { |
--- |
| 3358 |
return false; |
0 |
3358 |
return false; |
0 |
| 3359 |
} |
--- |
3359 |
} |
--- |
| 3360 |
bool IsKnownNoRecurse; |
--- |
3360 |
bool IsKnownNoRecurse; |
--- |
| 3361 |
return AA::hasAssumedIRAttr( |
0 |
3361 |
return AA::hasAssumedIRAttr( |
0 |
| 3362 |
A, this, IPos, DepClassTy::REQUIRED, IsKnownNoRecurse); |
0 |
3362 |
A, this, IPos, DepClassTy::REQUIRED, IsKnownNoRecurse); |
0 |
| 3363 |
}; |
0 |
3363 |
}; |
0 |
| 3364 |
|
--- |
3364 |
|
--- |
| 3365 |
bool UsedAssumedInformation = false; |
0 |
3365 |
bool UsedAssumedInformation = false; |
0 |
| 3366 |
if (!A.checkForAllCallLikeInstructions(CheckForWillReturn, *this, |
0 |
3366 |
if (!A.checkForAllCallLikeInstructions(CheckForWillReturn, *this, |
0 |
| 3367 |
UsedAssumedInformation)) |
--- |
3367 |
UsedAssumedInformation)) |
--- |
| 3368 |
return indicatePessimisticFixpoint(); |
0 |
3368 |
return indicatePessimisticFixpoint(); |
0 |
| 3369 |
|
--- |
3369 |
|
--- |
| 3370 |
return ChangeStatus::UNCHANGED; |
0 |
3370 |
return ChangeStatus::UNCHANGED; |
0 |
| 3371 |
} |
--- |
3371 |
} |
--- |
| 3372 |
|
--- |
3372 |
|
--- |
| 3373 |
/// See AbstractAttribute::getAsStr() |
--- |
3373 |
/// See AbstractAttribute::getAsStr() |
--- |
| 3374 |
const std::string getAsStr(Attributor *A) const override { |
0 |
3374 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 3375 |
return getAssumed() ? "willreturn" : "may-noreturn"; |
0 |
3375 |
return getAssumed() ? "willreturn" : "may-noreturn"; |
0 |
| 3376 |
} |
--- |
3376 |
} |
--- |
| 3377 |
}; |
--- |
3377 |
}; |
--- |
| 3378 |
|
--- |
3378 |
|
--- |
| 3379 |
struct AAWillReturnFunction final : AAWillReturnImpl { |
--- |
3379 |
struct AAWillReturnFunction final : AAWillReturnImpl { |
--- |
| 3380 |
AAWillReturnFunction(const IRPosition &IRP, Attributor &A) |
0 |
3380 |
AAWillReturnFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 3381 |
: AAWillReturnImpl(IRP, A) {} |
0 |
3381 |
: AAWillReturnImpl(IRP, A) {} |
0 |
| 3382 |
|
--- |
3382 |
|
--- |
| 3383 |
/// See AbstractAttribute::initialize(...). |
--- |
3383 |
/// See AbstractAttribute::initialize(...). |
--- |
| 3384 |
void initialize(Attributor &A) override { |
0 |
3384 |
void initialize(Attributor &A) override { |
0 |
| 3385 |
AAWillReturnImpl::initialize(A); |
0 |
3385 |
AAWillReturnImpl::initialize(A); |
0 |
| 3386 |
|
--- |
3386 |
|
--- |
| 3387 |
Function *F = getAnchorScope(); |
0 |
3387 |
Function *F = getAnchorScope(); |
0 |
| 3388 |
assert(F && "Did expect an anchor function"); |
0 |
3388 |
assert(F && "Did expect an anchor function"); |
0 |
| 3389 |
if (F->isDeclaration() || mayContainUnboundedCycle(*F, A)) |
0 |
3389 |
if (F->isDeclaration() || mayContainUnboundedCycle(*F, A)) |
0 |
| 3390 |
indicatePessimisticFixpoint(); |
0 |
3390 |
indicatePessimisticFixpoint(); |
0 |
| 3391 |
} |
0 |
3391 |
} |
0 |
| 3392 |
|
--- |
3392 |
|
--- |
| 3393 |
/// See AbstractAttribute::trackStatistics() |
--- |
3393 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 3394 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(willreturn) } |
0 |
3394 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(willreturn) } |
0 |
| 3395 |
}; |
--- |
3395 |
}; |
--- |
| 3396 |
|
--- |
3396 |
|
--- |
| 3397 |
/// WillReturn attribute deduction for a call sites. |
--- |
3397 |
/// WillReturn attribute deduction for a call sites. |
--- |
| 3398 |
struct AAWillReturnCallSite final : AAWillReturnImpl { |
--- |
3398 |
struct AAWillReturnCallSite final : AAWillReturnImpl { |
--- |
| 3399 |
AAWillReturnCallSite(const IRPosition &IRP, Attributor &A) |
0 |
3399 |
AAWillReturnCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 3400 |
: AAWillReturnImpl(IRP, A) {} |
0 |
3400 |
: AAWillReturnImpl(IRP, A) {} |
0 |
| 3401 |
|
--- |
3401 |
|
--- |
| 3402 |
/// See AbstractAttribute::updateImpl(...). |
--- |
3402 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 3403 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
3403 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 3404 |
if (isImpliedByMustprogressAndReadonly(A, /* KnownOnly */ false)) |
0 |
3404 |
if (isImpliedByMustprogressAndReadonly(A, /* KnownOnly */ false)) |
0 |
| 3405 |
return ChangeStatus::UNCHANGED; |
0 |
3405 |
return ChangeStatus::UNCHANGED; |
0 |
| 3406 |
|
--- |
3406 |
|
--- |
| 3407 |
// TODO: Once we have call site specific value information we can provide |
--- |
3407 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 3408 |
// call site specific liveness information and then it makes |
--- |
3408 |
// call site specific liveness information and then it makes |
--- |
| 3409 |
// sense to specialize attributes for call sites arguments instead of |
--- |
3409 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 3410 |
// redirecting requests to the callee argument. |
--- |
3410 |
// redirecting requests to the callee argument. |
--- |
| 3411 |
Function *F = getAssociatedFunction(); |
0 |
3411 |
Function *F = getAssociatedFunction(); |
0 |
| 3412 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
3412 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
| 3413 |
bool IsKnown; |
--- |
3413 |
bool IsKnown; |
--- |
| 3414 |
if (AA::hasAssumedIRAttr( |
0 |
3414 |
if (AA::hasAssumedIRAttr( |
0 |
| 3415 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnown)) |
--- |
3415 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnown)) |
--- |
| 3416 |
return ChangeStatus::UNCHANGED; |
0 |
3416 |
return ChangeStatus::UNCHANGED; |
0 |
| 3417 |
return indicatePessimisticFixpoint(); |
0 |
3417 |
return indicatePessimisticFixpoint(); |
0 |
| 3418 |
} |
--- |
3418 |
} |
--- |
| 3419 |
|
--- |
3419 |
|
--- |
| 3420 |
/// See AbstractAttribute::trackStatistics() |
--- |
3420 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 3421 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(willreturn); } |
0 |
3421 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(willreturn); } |
0 |
| 3422 |
}; |
--- |
3422 |
}; |
--- |
| 3423 |
} // namespace |
--- |
3423 |
} // namespace |
--- |
| 3424 |
|
--- |
3424 |
|
--- |
| 3425 |
/// -------------------AAIntraFnReachability Attribute-------------------------- |
--- |
3425 |
/// -------------------AAIntraFnReachability Attribute-------------------------- |
--- |
| 3426 |
|
--- |
3426 |
|
--- |
| 3427 |
/// All information associated with a reachability query. This boilerplate code |
--- |
3427 |
/// All information associated with a reachability query. This boilerplate code |
--- |
| 3428 |
/// is used by both AAIntraFnReachability and AAInterFnReachability, with |
--- |
3428 |
/// is used by both AAIntraFnReachability and AAInterFnReachability, with |
--- |
| 3429 |
/// different \p ToTy values. |
--- |
3429 |
/// different \p ToTy values. |
--- |
| 3430 |
template struct ReachabilityQueryInfo { |
--- |
3430 |
template struct ReachabilityQueryInfo { |
--- |
| 3431 |
enum class Reachable { |
--- |
3431 |
enum class Reachable { |
--- |
| 3432 |
No, |
--- |
3432 |
No, |
--- |
| 3433 |
Yes, |
--- |
3433 |
Yes, |
--- |
| 3434 |
}; |
--- |
3434 |
}; |
--- |
| 3435 |
|
--- |
3435 |
|
--- |
| 3436 |
/// Start here, |
--- |
3436 |
/// Start here, |
--- |
| 3437 |
const Instruction *From = nullptr; |
--- |
3437 |
const Instruction *From = nullptr; |
--- |
| 3438 |
/// reach this place, |
--- |
3438 |
/// reach this place, |
--- |
| 3439 |
const ToTy *To = nullptr; |
--- |
3439 |
const ToTy *To = nullptr; |
--- |
| 3440 |
/// without going through any of these instructions, |
--- |
3440 |
/// without going through any of these instructions, |
--- |
| 3441 |
const AA::InstExclusionSetTy *ExclusionSet = nullptr; |
--- |
3441 |
const AA::InstExclusionSetTy *ExclusionSet = nullptr; |
--- |
| 3442 |
/// and remember if it worked: |
--- |
3442 |
/// and remember if it worked: |
--- |
| 3443 |
Reachable Result = Reachable::No; |
--- |
3443 |
Reachable Result = Reachable::No; |
--- |
| 3444 |
|
--- |
3444 |
|
--- |
| 3445 |
ReachabilityQueryInfo(const Instruction *From, const ToTy *To) |
2 |
3445 |
ReachabilityQueryInfo(const Instruction *From, const ToTy *To) |
2 |
| 3446 |
: From(From), To(To) {} |
2 |
3446 |
: From(From), To(To) {} |
2 |
| 3447 |
|
--- |
3447 |
|
--- |
| 3448 |
/// Constructor replacement to ensure unique and stable sets are used for the |
--- |
3448 |
/// Constructor replacement to ensure unique and stable sets are used for the |
--- |
| 3449 |
/// cache. |
--- |
3449 |
/// cache. |
--- |
| 3450 |
ReachabilityQueryInfo(Attributor &A, const Instruction &From, const ToTy &To, |
0 |
3450 |
ReachabilityQueryInfo(Attributor &A, const Instruction &From, const ToTy &To, |
0 |
| 3451 |
const AA::InstExclusionSetTy *ES, bool MakeUnique) |
--- |
3451 |
const AA::InstExclusionSetTy *ES, bool MakeUnique) |
--- |
| 3452 |
: From(&From), To(&To), ExclusionSet(ES) { |
0 |
3452 |
: From(&From), To(&To), ExclusionSet(ES) { |
0 |
| 3453 |
|
--- |
3453 |
|
--- |
| 3454 |
if (!ES || ES->empty()) { |
0 |
3454 |
if (!ES || ES->empty()) { |
0 |
| 3455 |
ExclusionSet = nullptr; |
0 |
3455 |
ExclusionSet = nullptr; |
0 |
| 3456 |
} else if (MakeUnique) { |
0 |
3456 |
} else if (MakeUnique) { |
0 |
| 3457 |
ExclusionSet = A.getInfoCache().getOrCreateUniqueBlockExecutionSet(ES); |
0 |
3457 |
ExclusionSet = A.getInfoCache().getOrCreateUniqueBlockExecutionSet(ES); |
0 |
| 3458 |
} |
--- |
3458 |
} |
--- |
| 3459 |
} |
0 |
3459 |
} |
0 |
| 3460 |
|
--- |
3460 |
|
--- |
| 3461 |
ReachabilityQueryInfo(const ReachabilityQueryInfo &RQI) |
--- |
3461 |
ReachabilityQueryInfo(const ReachabilityQueryInfo &RQI) |
--- |
| 3462 |
: From(RQI.From), To(RQI.To), ExclusionSet(RQI.ExclusionSet) {} |
--- |
3462 |
: From(RQI.From), To(RQI.To), ExclusionSet(RQI.ExclusionSet) {} |
--- |
| 3463 |
}; |
--- |
3463 |
}; |
--- |
| 3464 |
|
--- |
3464 |
|
--- |
| 3465 |
namespace llvm { |
--- |
3465 |
namespace llvm { |
--- |
| 3466 |
template struct DenseMapInfo *> { |
--- |
3466 |
template struct DenseMapInfo *> { |
--- |
| 3467 |
using InstSetDMI = DenseMapInfo; |
--- |
3467 |
using InstSetDMI = DenseMapInfo; |
--- |
| 3468 |
using PairDMI = DenseMapInfo>; |
--- |
3468 |
using PairDMI = DenseMapInfo>; |
--- |
| 3469 |
|
--- |
3469 |
|
--- |
| 3470 |
static ReachabilityQueryInfo EmptyKey; |
--- |
3470 |
static ReachabilityQueryInfo EmptyKey; |
--- |
| 3471 |
static ReachabilityQueryInfo TombstoneKey; |
--- |
3471 |
static ReachabilityQueryInfo TombstoneKey; |
--- |
| 3472 |
|
--- |
3472 |
|
--- |
| 3473 |
static inline ReachabilityQueryInfo *getEmptyKey() { return &EmptyKey; } |
0 |
3473 |
static inline ReachabilityQueryInfo *getEmptyKey() { return &EmptyKey; } |
0 |
| 3474 |
static inline ReachabilityQueryInfo *getTombstoneKey() { |
0 |
3474 |
static inline ReachabilityQueryInfo *getTombstoneKey() { |
0 |
| 3475 |
return &TombstoneKey; |
0 |
3475 |
return &TombstoneKey; |
0 |
| 3476 |
} |
--- |
3476 |
} |
--- |
| 3477 |
static unsigned getHashValue(const ReachabilityQueryInfo *RQI) { |
0 |
3477 |
static unsigned getHashValue(const ReachabilityQueryInfo *RQI) { |
0 |
| 3478 |
unsigned H = PairDMI ::getHashValue({RQI->From, RQI->To}); |
0 |
3478 |
unsigned H = PairDMI ::getHashValue({RQI->From, RQI->To}); |
0 |
| 3479 |
H += InstSetDMI::getHashValue(RQI->ExclusionSet); |
0 |
3479 |
H += InstSetDMI::getHashValue(RQI->ExclusionSet); |
0 |
| 3480 |
return H; |
0 |
3480 |
return H; |
0 |
| 3481 |
} |
--- |
3481 |
} |
--- |
| 3482 |
static bool isEqual(const ReachabilityQueryInfo *LHS, |
0 |
3482 |
static bool isEqual(const ReachabilityQueryInfo *LHS, |
0 |
| 3483 |
const ReachabilityQueryInfo *RHS) { |
--- |
3483 |
const ReachabilityQueryInfo *RHS) { |
--- |
| 3484 |
if (!PairDMI::isEqual({LHS->From, LHS->To}, {RHS->From, RHS->To})) |
0 |
3484 |
if (!PairDMI::isEqual({LHS->From, LHS->To}, {RHS->From, RHS->To})) |
0 |
| 3485 |
return false; |
0 |
3485 |
return false; |
0 |
| 3486 |
return InstSetDMI::isEqual(LHS->ExclusionSet, RHS->ExclusionSet); |
0 |
3486 |
return InstSetDMI::isEqual(LHS->ExclusionSet, RHS->ExclusionSet); |
0 |
| 3487 |
} |
--- |
3487 |
} |
--- |
| 3488 |
}; |
--- |
3488 |
}; |
--- |
| 3489 |
|
--- |
3489 |
|
--- |
| 3490 |
#define DefineKeys(ToTy) \ |
--- |
3490 |
#define DefineKeys(ToTy) \ |
--- |
| 3491 |
template <> \ |
--- |
3491 |
template <> \ |
--- |
| 3492 |
ReachabilityQueryInfo \ |
--- |
3492 |
ReachabilityQueryInfo \ |
--- |
| 3493 |
DenseMapInfo *>::EmptyKey = \ |
--- |
3493 |
DenseMapInfo *>::EmptyKey = \ |
--- |
| 3494 |
ReachabilityQueryInfo( \ |
--- |
3494 |
ReachabilityQueryInfo( \ |
--- |
| 3495 |
DenseMapInfo::getEmptyKey(), \ |
--- |
3495 |
DenseMapInfo::getEmptyKey(), \ |
--- |
| 3496 |
DenseMapInfo::getEmptyKey()); \ |
--- |
3496 |
DenseMapInfo::getEmptyKey()); \ |
--- |
| 3497 |
template <> \ |
--- |
3497 |
template <> \ |
--- |
| 3498 |
ReachabilityQueryInfo \ |
--- |
3498 |
ReachabilityQueryInfo \ |
--- |
| 3499 |
DenseMapInfo *>::TombstoneKey = \ |
--- |
3499 |
DenseMapInfo *>::TombstoneKey = \ |
--- |
| 3500 |
ReachabilityQueryInfo( \ |
--- |
3500 |
ReachabilityQueryInfo( \ |
--- |
| 3501 |
DenseMapInfo::getTombstoneKey(), \ |
--- |
3501 |
DenseMapInfo::getTombstoneKey(), \ |
--- |
| 3502 |
DenseMapInfo::getTombstoneKey()); |
--- |
3502 |
DenseMapInfo::getTombstoneKey()); |
--- |
| 3503 |
|
--- |
3503 |
|
--- |
| 3504 |
DefineKeys(Instruction) DefineKeys(Function) |
--- |
3504 |
DefineKeys(Instruction) DefineKeys(Function) |
--- |
| 3505 |
#undef DefineKeys |
--- |
3505 |
#undef DefineKeys |
--- |
| 3506 |
|
--- |
3506 |
|
--- |
| 3507 |
} // namespace llvm |
--- |
3507 |
} // namespace llvm |
--- |
| 3508 |
|
--- |
3508 |
|
--- |
| 3509 |
namespace { |
--- |
3509 |
namespace { |
--- |
| 3510 |
|
--- |
3510 |
|
--- |
| 3511 |
template |
--- |
3511 |
template |
--- |
| 3512 |
struct CachedReachabilityAA : public BaseTy { |
--- |
3512 |
struct CachedReachabilityAA : public BaseTy { |
--- |
| 3513 |
using RQITy = ReachabilityQueryInfo; |
--- |
3513 |
using RQITy = ReachabilityQueryInfo; |
--- |
| 3514 |
|
--- |
3514 |
|
--- |
| 3515 |
CachedReachabilityAA(const IRPosition &IRP, Attributor &A) : BaseTy(IRP, A) {} |
0 |
3515 |
CachedReachabilityAA(const IRPosition &IRP, Attributor &A) : BaseTy(IRP, A) {} |
0 |
| 3516 |
|
--- |
3516 |
|
--- |
| 3517 |
/// See AbstractAttribute::isQueryAA. |
--- |
3517 |
/// See AbstractAttribute::isQueryAA. |
--- |
| 3518 |
bool isQueryAA() const override { return true; } |
0 |
3518 |
bool isQueryAA() const override { return true; } |
0 |
| 3519 |
|
--- |
3519 |
|
--- |
| 3520 |
/// See AbstractAttribute::updateImpl(...). |
--- |
3520 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 3521 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
3521 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 3522 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
3522 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 3523 |
InUpdate = true; |
0 |
3523 |
InUpdate = true; |
0 |
| 3524 |
for (unsigned u = 0, e = QueryVector.size(); u < e; ++u) { |
0 |
3524 |
for (unsigned u = 0, e = QueryVector.size(); u < e; ++u) { |
0 |
| 3525 |
RQITy *RQI = QueryVector[u]; |
0 |
3525 |
RQITy *RQI = QueryVector[u]; |
0 |
| 3526 |
if (RQI->Result == RQITy::Reachable::No && isReachableImpl(A, *RQI)) |
0 |
3526 |
if (RQI->Result == RQITy::Reachable::No && isReachableImpl(A, *RQI)) |
0 |
| 3527 |
Changed = ChangeStatus::CHANGED; |
0 |
3527 |
Changed = ChangeStatus::CHANGED; |
0 |
| 3528 |
} |
--- |
3528 |
} |
--- |
| 3529 |
InUpdate = false; |
0 |
3529 |
InUpdate = false; |
0 |
| 3530 |
return Changed; |
0 |
3530 |
return Changed; |
0 |
| 3531 |
} |
--- |
3531 |
} |
--- |
| 3532 |
|
--- |
3532 |
|
--- |
| 3533 |
virtual bool isReachableImpl(Attributor &A, RQITy &RQI) = 0; |
--- |
3533 |
virtual bool isReachableImpl(Attributor &A, RQITy &RQI) = 0; |
--- |
| 3534 |
|
--- |
3534 |
|
--- |
| 3535 |
bool rememberResult(Attributor &A, typename RQITy::Reachable Result, |
0 |
3535 |
bool rememberResult(Attributor &A, typename RQITy::Reachable Result, |
0 |
| 3536 |
RQITy &RQI, bool UsedExclusionSet) { |
--- |
3536 |
RQITy &RQI, bool UsedExclusionSet) { |
--- |
| 3537 |
RQI.Result = Result; |
0 |
3537 |
RQI.Result = Result; |
0 |
| 3538 |
|
--- |
3538 |
|
--- |
| 3539 |
// Remove the temporary RQI from the cache. |
--- |
3539 |
// Remove the temporary RQI from the cache. |
--- |
| 3540 |
if (!InUpdate) |
0 |
3540 |
if (!InUpdate) |
0 |
| 3541 |
QueryCache.erase(&RQI); |
0 |
3541 |
QueryCache.erase(&RQI); |
0 |
| 3542 |
|
--- |
3542 |
|
--- |
| 3543 |
// Insert a plain RQI (w/o exclusion set) if that makes sense. Two options: |
--- |
3543 |
// Insert a plain RQI (w/o exclusion set) if that makes sense. Two options: |
--- |
| 3544 |
// 1) If it is reachable, it doesn't matter if we have an exclusion set for |
--- |
3544 |
// 1) If it is reachable, it doesn't matter if we have an exclusion set for |
--- |
| 3545 |
// this query. 2) We did not use the exclusion set, potentially because |
--- |
3545 |
// this query. 2) We did not use the exclusion set, potentially because |
--- |
| 3546 |
// there is none. |
--- |
3546 |
// there is none. |
--- |
| 3547 |
if (Result == RQITy::Reachable::Yes || !UsedExclusionSet) { |
0 |
3547 |
if (Result == RQITy::Reachable::Yes || !UsedExclusionSet) { |
0 |
| 3548 |
RQITy PlainRQI(RQI.From, RQI.To); |
0 |
3548 |
RQITy PlainRQI(RQI.From, RQI.To); |
0 |
| 3549 |
if (!QueryCache.count(&PlainRQI)) { |
0 |
3549 |
if (!QueryCache.count(&PlainRQI)) { |
0 |
| 3550 |
RQITy *RQIPtr = new (A.Allocator) RQITy(RQI.From, RQI.To); |
0 |
3550 |
RQITy *RQIPtr = new (A.Allocator) RQITy(RQI.From, RQI.To); |
0 |
| 3551 |
RQIPtr->Result = Result; |
0 |
3551 |
RQIPtr->Result = Result; |
0 |
| 3552 |
QueryVector.push_back(RQIPtr); |
0 |
3552 |
QueryVector.push_back(RQIPtr); |
0 |
| 3553 |
QueryCache.insert(RQIPtr); |
0 |
3553 |
QueryCache.insert(RQIPtr); |
0 |
| 3554 |
} |
--- |
3554 |
} |
--- |
| 3555 |
} |
--- |
3555 |
} |
--- |
| 3556 |
|
--- |
3556 |
|
--- |
| 3557 |
// Check if we need to insert a new permanent RQI with the exclusion set. |
--- |
3557 |
// Check if we need to insert a new permanent RQI with the exclusion set. |
--- |
| 3558 |
if (!InUpdate && Result != RQITy::Reachable::Yes && UsedExclusionSet) { |
0 |
3558 |
if (!InUpdate && Result != RQITy::Reachable::Yes && UsedExclusionSet) { |
0 |
| 3559 |
assert((!RQI.ExclusionSet || !RQI.ExclusionSet->empty()) && |
0 |
3559 |
assert((!RQI.ExclusionSet || !RQI.ExclusionSet->empty()) && |
0 |
| 3560 |
"Did not expect empty set!"); |
--- |
3560 |
"Did not expect empty set!"); |
--- |
| 3561 |
RQITy *RQIPtr = new (A.Allocator) |
0 |
3561 |
RQITy *RQIPtr = new (A.Allocator) |
0 |
| 3562 |
RQITy(A, *RQI.From, *RQI.To, RQI.ExclusionSet, true); |
0 |
3562 |
RQITy(A, *RQI.From, *RQI.To, RQI.ExclusionSet, true); |
0 |
| 3563 |
assert(RQIPtr->Result == RQITy::Reachable::No && "Already reachable?"); |
0 |
3563 |
assert(RQIPtr->Result == RQITy::Reachable::No && "Already reachable?"); |
0 |
| 3564 |
RQIPtr->Result = Result; |
0 |
3564 |
RQIPtr->Result = Result; |
0 |
| 3565 |
assert(!QueryCache.count(RQIPtr)); |
0 |
3565 |
assert(!QueryCache.count(RQIPtr)); |
0 |
| 3566 |
QueryVector.push_back(RQIPtr); |
0 |
3566 |
QueryVector.push_back(RQIPtr); |
0 |
| 3567 |
QueryCache.insert(RQIPtr); |
0 |
3567 |
QueryCache.insert(RQIPtr); |
0 |
| 3568 |
} |
--- |
3568 |
} |
--- |
| 3569 |
|
--- |
3569 |
|
--- |
| 3570 |
if (Result == RQITy::Reachable::No && !InUpdate) |
0 |
3570 |
if (Result == RQITy::Reachable::No && !InUpdate) |
0 |
| 3571 |
A.registerForUpdate(*this); |
0 |
3571 |
A.registerForUpdate(*this); |
0 |
| 3572 |
return Result == RQITy::Reachable::Yes; |
0 |
3572 |
return Result == RQITy::Reachable::Yes; |
0 |
| 3573 |
} |
--- |
3573 |
} |
--- |
| 3574 |
|
--- |
3574 |
|
--- |
| 3575 |
const std::string getAsStr(Attributor *A) const override { |
0 |
3575 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 3576 |
// TODO: Return the number of reachable queries. |
--- |
3576 |
// TODO: Return the number of reachable queries. |
--- |
| 3577 |
return "#queries(" + std::to_string(QueryVector.size()) + ")"; |
0 |
3577 |
return "#queries(" + std::to_string(QueryVector.size()) + ")"; |
0 |
| 3578 |
} |
--- |
3578 |
} |
--- |
| 3579 |
|
--- |
3579 |
|
--- |
| 3580 |
bool checkQueryCache(Attributor &A, RQITy &StackRQI, |
0 |
3580 |
bool checkQueryCache(Attributor &A, RQITy &StackRQI, |
0 |
| 3581 |
typename RQITy::Reachable &Result) { |
--- |
3581 |
typename RQITy::Reachable &Result) { |
--- |
| 3582 |
if (!this->getState().isValidState()) { |
0 |
3582 |
if (!this->getState().isValidState()) { |
0 |
| 3583 |
Result = RQITy::Reachable::Yes; |
0 |
3583 |
Result = RQITy::Reachable::Yes; |
0 |
| 3584 |
return true; |
0 |
3584 |
return true; |
0 |
| 3585 |
} |
--- |
3585 |
} |
--- |
| 3586 |
|
--- |
3586 |
|
--- |
| 3587 |
// If we have an exclusion set we might be able to find our answer by |
--- |
3587 |
// If we have an exclusion set we might be able to find our answer by |
--- |
| 3588 |
// ignoring it first. |
--- |
3588 |
// ignoring it first. |
--- |
| 3589 |
if (StackRQI.ExclusionSet) { |
0 |
3589 |
if (StackRQI.ExclusionSet) { |
0 |
| 3590 |
RQITy PlainRQI(StackRQI.From, StackRQI.To); |
0 |
3590 |
RQITy PlainRQI(StackRQI.From, StackRQI.To); |
0 |
| 3591 |
auto It = QueryCache.find(&PlainRQI); |
0 |
3591 |
auto It = QueryCache.find(&PlainRQI); |
0 |
| 3592 |
if (It != QueryCache.end() && (*It)->Result == RQITy::Reachable::No) { |
0 |
3592 |
if (It != QueryCache.end() && (*It)->Result == RQITy::Reachable::No) { |
0 |
| 3593 |
Result = RQITy::Reachable::No; |
0 |
3593 |
Result = RQITy::Reachable::No; |
0 |
| 3594 |
return true; |
0 |
3594 |
return true; |
0 |
| 3595 |
} |
--- |
3595 |
} |
--- |
| 3596 |
} |
--- |
3596 |
} |
--- |
| 3597 |
|
--- |
3597 |
|
--- |
| 3598 |
auto It = QueryCache.find(&StackRQI); |
0 |
3598 |
auto It = QueryCache.find(&StackRQI); |
0 |
| 3599 |
if (It != QueryCache.end()) { |
0 |
3599 |
if (It != QueryCache.end()) { |
0 |
| 3600 |
Result = (*It)->Result; |
0 |
3600 |
Result = (*It)->Result; |
0 |
| 3601 |
return true; |
0 |
3601 |
return true; |
0 |
| 3602 |
} |
--- |
3602 |
} |
--- |
| 3603 |
|
--- |
3603 |
|
--- |
| 3604 |
// Insert a temporary for recursive queries. We will replace it with a |
--- |
3604 |
// Insert a temporary for recursive queries. We will replace it with a |
--- |
| 3605 |
// permanent entry later. |
--- |
3605 |
// permanent entry later. |
--- |
| 3606 |
QueryCache.insert(&StackRQI); |
0 |
3606 |
QueryCache.insert(&StackRQI); |
0 |
| 3607 |
return false; |
0 |
3607 |
return false; |
0 |
| 3608 |
} |
--- |
3608 |
} |
--- |
| 3609 |
|
--- |
3609 |
|
--- |
| 3610 |
private: |
--- |
3610 |
private: |
--- |
| 3611 |
bool InUpdate = false; |
--- |
3611 |
bool InUpdate = false; |
--- |
| 3612 |
SmallVector QueryVector; |
--- |
3612 |
SmallVector QueryVector; |
--- |
| 3613 |
DenseSet QueryCache; |
--- |
3613 |
DenseSet QueryCache; |
--- |
| 3614 |
}; |
--- |
3614 |
}; |
--- |
| 3615 |
|
--- |
3615 |
|
--- |
| 3616 |
struct AAIntraFnReachabilityFunction final |
--- |
3616 |
struct AAIntraFnReachabilityFunction final |
--- |
| 3617 |
: public CachedReachabilityAA { |
--- |
3617 |
: public CachedReachabilityAA { |
--- |
| 3618 |
using Base = CachedReachabilityAA; |
--- |
3618 |
using Base = CachedReachabilityAA; |
--- |
| 3619 |
AAIntraFnReachabilityFunction(const IRPosition &IRP, Attributor &A) |
0 |
3619 |
AAIntraFnReachabilityFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 3620 |
: Base(IRP, A) {} |
0 |
3620 |
: Base(IRP, A) {} |
0 |
| 3621 |
|
--- |
3621 |
|
--- |
| 3622 |
bool isAssumedReachable( |
0 |
3622 |
bool isAssumedReachable( |
0 |
| 3623 |
Attributor &A, const Instruction &From, const Instruction &To, |
--- |
3623 |
Attributor &A, const Instruction &From, const Instruction &To, |
--- |
| 3624 |
const AA::InstExclusionSetTy *ExclusionSet) const override { |
--- |
3624 |
const AA::InstExclusionSetTy *ExclusionSet) const override { |
--- |
| 3625 |
auto *NonConstThis = const_cast(this); |
0 |
3625 |
auto *NonConstThis = const_cast(this); |
0 |
| 3626 |
if (&From == &To) |
0 |
3626 |
if (&From == &To) |
0 |
| 3627 |
return true; |
0 |
3627 |
return true; |
0 |
| 3628 |
|
--- |
3628 |
|
--- |
| 3629 |
RQITy StackRQI(A, From, To, ExclusionSet, false); |
0 |
3629 |
RQITy StackRQI(A, From, To, ExclusionSet, false); |
0 |
| 3630 |
typename RQITy::Reachable Result; |
--- |
3630 |
typename RQITy::Reachable Result; |
--- |
| 3631 |
if (!NonConstThis->checkQueryCache(A, StackRQI, Result)) |
0 |
3631 |
if (!NonConstThis->checkQueryCache(A, StackRQI, Result)) |
0 |
| 3632 |
return NonConstThis->isReachableImpl(A, StackRQI); |
0 |
3632 |
return NonConstThis->isReachableImpl(A, StackRQI); |
0 |
| 3633 |
return Result == RQITy::Reachable::Yes; |
0 |
3633 |
return Result == RQITy::Reachable::Yes; |
0 |
| 3634 |
} |
--- |
3634 |
} |
--- |
| 3635 |
|
--- |
3635 |
|
--- |
| 3636 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
3636 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 3637 |
// We only depend on liveness. DeadEdges is all we care about, check if any |
--- |
3637 |
// We only depend on liveness. DeadEdges is all we care about, check if any |
--- |
| 3638 |
// of them changed. |
--- |
3638 |
// of them changed. |
--- |
| 3639 |
auto *LivenessAA = |
--- |
3639 |
auto *LivenessAA = |
--- |
| 3640 |
A.getAAFor(*this, getIRPosition(), DepClassTy::OPTIONAL); |
0 |
3640 |
A.getAAFor(*this, getIRPosition(), DepClassTy::OPTIONAL); |
0 |
| 3641 |
if (LivenessAA && llvm::all_of(DeadEdges, [&](const auto &DeadEdge) { |
0 |
3641 |
if (LivenessAA && llvm::all_of(DeadEdges, [&](const auto &DeadEdge) { |
0 |
| 3642 |
return LivenessAA->isEdgeDead(DeadEdge.first, DeadEdge.second); |
0 |
3642 |
return LivenessAA->isEdgeDead(DeadEdge.first, DeadEdge.second); |
0 |
| 3643 |
})) { |
--- |
3643 |
})) { |
--- |
| 3644 |
return ChangeStatus::UNCHANGED; |
0 |
3644 |
return ChangeStatus::UNCHANGED; |
0 |
| 3645 |
} |
--- |
3645 |
} |
--- |
| 3646 |
DeadEdges.clear(); |
0 |
3646 |
DeadEdges.clear(); |
0 |
| 3647 |
return Base::updateImpl(A); |
0 |
3647 |
return Base::updateImpl(A); |
0 |
| 3648 |
} |
--- |
3648 |
} |
--- |
| 3649 |
|
--- |
3649 |
|
--- |
| 3650 |
bool isReachableImpl(Attributor &A, RQITy &RQI) override { |
0 |
3650 |
bool isReachableImpl(Attributor &A, RQITy &RQI) override { |
0 |
| 3651 |
const Instruction *Origin = RQI.From; |
0 |
3651 |
const Instruction *Origin = RQI.From; |
0 |
| 3652 |
bool UsedExclusionSet = false; |
0 |
3652 |
bool UsedExclusionSet = false; |
0 |
| 3653 |
|
--- |
3653 |
|
--- |
| 3654 |
auto WillReachInBlock = [&](const Instruction &From, const Instruction &To, |
0 |
3654 |
auto WillReachInBlock = [&](const Instruction &From, const Instruction &To, |
0 |
| 3655 |
const AA::InstExclusionSetTy *ExclusionSet) { |
--- |
3655 |
const AA::InstExclusionSetTy *ExclusionSet) { |
--- |
| 3656 |
const Instruction *IP = &From; |
0 |
3656 |
const Instruction *IP = &From; |
0 |
| 3657 |
while (IP && IP != &To) { |
0 |
3657 |
while (IP && IP != &To) { |
0 |
| 3658 |
if (ExclusionSet && IP != Origin && ExclusionSet->count(IP)) { |
0 |
3658 |
if (ExclusionSet && IP != Origin && ExclusionSet->count(IP)) { |
0 |
| 3659 |
UsedExclusionSet = true; |
0 |
3659 |
UsedExclusionSet = true; |
0 |
| 3660 |
break; |
0 |
3660 |
break; |
0 |
| 3661 |
} |
--- |
3661 |
} |
--- |
| 3662 |
IP = IP->getNextNode(); |
0 |
3662 |
IP = IP->getNextNode(); |
0 |
| 3663 |
} |
--- |
3663 |
} |
--- |
| 3664 |
return IP == &To; |
0 |
3664 |
return IP == &To; |
0 |
| 3665 |
}; |
0 |
3665 |
}; |
0 |
| 3666 |
|
--- |
3666 |
|
--- |
| 3667 |
const BasicBlock *FromBB = RQI.From->getParent(); |
0 |
3667 |
const BasicBlock *FromBB = RQI.From->getParent(); |
0 |
| 3668 |
const BasicBlock *ToBB = RQI.To->getParent(); |
0 |
3668 |
const BasicBlock *ToBB = RQI.To->getParent(); |
0 |
| 3669 |
assert(FromBB->getParent() == ToBB->getParent() && |
0 |
3669 |
assert(FromBB->getParent() == ToBB->getParent() && |
0 |
| 3670 |
"Not an intra-procedural query!"); |
--- |
3670 |
"Not an intra-procedural query!"); |
--- |
| 3671 |
|
--- |
3671 |
|
--- |
| 3672 |
// Check intra-block reachability, however, other reaching paths are still |
--- |
3672 |
// Check intra-block reachability, however, other reaching paths are still |
--- |
| 3673 |
// possible. |
--- |
3673 |
// possible. |
--- |
| 3674 |
if (FromBB == ToBB && |
0 |
3674 |
if (FromBB == ToBB && |
0 |
| 3675 |
WillReachInBlock(*RQI.From, *RQI.To, RQI.ExclusionSet)) |
0 |
3675 |
WillReachInBlock(*RQI.From, *RQI.To, RQI.ExclusionSet)) |
0 |
| 3676 |
return rememberResult(A, RQITy::Reachable::Yes, RQI, UsedExclusionSet); |
0 |
3676 |
return rememberResult(A, RQITy::Reachable::Yes, RQI, UsedExclusionSet); |
0 |
| 3677 |
|
--- |
3677 |
|
--- |
| 3678 |
// Check if reaching the ToBB block is sufficient or if even that would not |
--- |
3678 |
// Check if reaching the ToBB block is sufficient or if even that would not |
--- |
| 3679 |
// ensure reaching the target. In the latter case we are done. |
--- |
3679 |
// ensure reaching the target. In the latter case we are done. |
--- |
| 3680 |
if (!WillReachInBlock(ToBB->front(), *RQI.To, RQI.ExclusionSet)) |
0 |
3680 |
if (!WillReachInBlock(ToBB->front(), *RQI.To, RQI.ExclusionSet)) |
0 |
| 3681 |
return rememberResult(A, RQITy::Reachable::No, RQI, UsedExclusionSet); |
0 |
3681 |
return rememberResult(A, RQITy::Reachable::No, RQI, UsedExclusionSet); |
0 |
| 3682 |
|
--- |
3682 |
|
--- |
| 3683 |
SmallPtrSet ExclusionBlocks; |
0 |
3683 |
SmallPtrSet ExclusionBlocks; |
0 |
| 3684 |
if (RQI.ExclusionSet) |
0 |
3684 |
if (RQI.ExclusionSet) |
0 |
| 3685 |
for (auto *I : *RQI.ExclusionSet) |
0 |
3685 |
for (auto *I : *RQI.ExclusionSet) |
0 |
| 3686 |
ExclusionBlocks.insert(I->getParent()); |
0 |
3686 |
ExclusionBlocks.insert(I->getParent()); |
0 |
| 3687 |
|
--- |
3687 |
|
--- |
| 3688 |
// Check if we make it out of the FromBB block at all. |
--- |
3688 |
// Check if we make it out of the FromBB block at all. |
--- |
| 3689 |
if (ExclusionBlocks.count(FromBB) && |
0 |
3689 |
if (ExclusionBlocks.count(FromBB) && |
0 |
| 3690 |
!WillReachInBlock(*RQI.From, *FromBB->getTerminator(), |
0 |
3690 |
!WillReachInBlock(*RQI.From, *FromBB->getTerminator(), |
0 |
| 3691 |
RQI.ExclusionSet)) |
--- |
3691 |
RQI.ExclusionSet)) |
--- |
| 3692 |
return rememberResult(A, RQITy::Reachable::No, RQI, UsedExclusionSet); |
0 |
3692 |
return rememberResult(A, RQITy::Reachable::No, RQI, UsedExclusionSet); |
0 |
| 3693 |
|
--- |
3693 |
|
--- |
| 3694 |
SmallPtrSet Visited; |
0 |
3694 |
SmallPtrSet Visited; |
0 |
| 3695 |
SmallVector Worklist; |
0 |
3695 |
SmallVector Worklist; |
0 |
| 3696 |
Worklist.push_back(FromBB); |
0 |
3696 |
Worklist.push_back(FromBB); |
0 |
| 3697 |
|
--- |
3697 |
|
--- |
| 3698 |
DenseSet> LocalDeadEdges; |
0 |
3698 |
DenseSet> LocalDeadEdges; |
0 |
| 3699 |
auto *LivenessAA = |
--- |
3699 |
auto *LivenessAA = |
--- |
| 3700 |
A.getAAFor(*this, getIRPosition(), DepClassTy::OPTIONAL); |
0 |
3700 |
A.getAAFor(*this, getIRPosition(), DepClassTy::OPTIONAL); |
0 |
| 3701 |
while (!Worklist.empty()) { |
0 |
3701 |
while (!Worklist.empty()) { |
0 |
| 3702 |
const BasicBlock *BB = Worklist.pop_back_val(); |
0 |
3702 |
const BasicBlock *BB = Worklist.pop_back_val(); |
0 |
| 3703 |
if (!Visited.insert(BB).second) |
0 |
3703 |
if (!Visited.insert(BB).second) |
0 |
| 3704 |
continue; |
0 |
3704 |
continue; |
0 |
| 3705 |
for (const BasicBlock *SuccBB : successors(BB)) { |
0 |
3705 |
for (const BasicBlock *SuccBB : successors(BB)) { |
0 |
| 3706 |
if (LivenessAA && LivenessAA->isEdgeDead(BB, SuccBB)) { |
0 |
3706 |
if (LivenessAA && LivenessAA->isEdgeDead(BB, SuccBB)) { |
0 |
| 3707 |
LocalDeadEdges.insert({BB, SuccBB}); |
0 |
3707 |
LocalDeadEdges.insert({BB, SuccBB}); |
0 |
| 3708 |
continue; |
0 |
3708 |
continue; |
0 |
| 3709 |
} |
--- |
3709 |
} |
--- |
| 3710 |
// We checked before if we just need to reach the ToBB block. |
--- |
3710 |
// We checked before if we just need to reach the ToBB block. |
--- |
| 3711 |
if (SuccBB == ToBB) |
0 |
3711 |
if (SuccBB == ToBB) |
0 |
| 3712 |
return rememberResult(A, RQITy::Reachable::Yes, RQI, |
0 |
3712 |
return rememberResult(A, RQITy::Reachable::Yes, RQI, |
0 |
| 3713 |
UsedExclusionSet); |
0 |
3713 |
UsedExclusionSet); |
0 |
| 3714 |
if (ExclusionBlocks.count(SuccBB)) { |
0 |
3714 |
if (ExclusionBlocks.count(SuccBB)) { |
0 |
| 3715 |
UsedExclusionSet = true; |
0 |
3715 |
UsedExclusionSet = true; |
0 |
| 3716 |
continue; |
0 |
3716 |
continue; |
0 |
| 3717 |
} |
--- |
3717 |
} |
--- |
| 3718 |
Worklist.push_back(SuccBB); |
0 |
3718 |
Worklist.push_back(SuccBB); |
0 |
| 3719 |
} |
--- |
3719 |
} |
--- |
| 3720 |
} |
--- |
3720 |
} |
--- |
| 3721 |
|
--- |
3721 |
|
--- |
| 3722 |
DeadEdges.insert(LocalDeadEdges.begin(), LocalDeadEdges.end()); |
0 |
3722 |
DeadEdges.insert(LocalDeadEdges.begin(), LocalDeadEdges.end()); |
0 |
| 3723 |
return rememberResult(A, RQITy::Reachable::No, RQI, UsedExclusionSet); |
0 |
3723 |
return rememberResult(A, RQITy::Reachable::No, RQI, UsedExclusionSet); |
0 |
| 3724 |
} |
0 |
3724 |
} |
0 |
| 3725 |
|
--- |
3725 |
|
--- |
| 3726 |
/// See AbstractAttribute::trackStatistics() |
--- |
3726 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 3727 |
void trackStatistics() const override {} |
0 |
3727 |
void trackStatistics() const override {} |
0 |
| 3728 |
|
--- |
3728 |
|
--- |
| 3729 |
private: |
--- |
3729 |
private: |
--- |
| 3730 |
// Set of assumed dead edges we used in the last query. If any changes we |
--- |
3730 |
// Set of assumed dead edges we used in the last query. If any changes we |
--- |
| 3731 |
// update the state. |
--- |
3731 |
// update the state. |
--- |
| 3732 |
DenseSet> DeadEdges; |
--- |
3732 |
DenseSet> DeadEdges; |
--- |
| 3733 |
}; |
--- |
3733 |
}; |
--- |
| 3734 |
} // namespace |
--- |
3734 |
} // namespace |
--- |
| 3735 |
|
--- |
3735 |
|
--- |
| 3736 |
/// ------------------------ NoAlias Argument Attribute ------------------------ |
--- |
3736 |
/// ------------------------ NoAlias Argument Attribute ------------------------ |
--- |
| 3737 |
|
--- |
3737 |
|
--- |
| 3738 |
bool AANoAlias::isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
3738 |
bool AANoAlias::isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
| 3739 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
3739 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 3740 |
bool IgnoreSubsumingPositions) { |
--- |
3740 |
bool IgnoreSubsumingPositions) { |
--- |
| 3741 |
assert(ImpliedAttributeKind == Attribute::NoAlias && |
0 |
3741 |
assert(ImpliedAttributeKind == Attribute::NoAlias && |
0 |
| 3742 |
"Unexpected attribute kind"); |
--- |
3742 |
"Unexpected attribute kind"); |
--- |
| 3743 |
Value *Val = &IRP.getAssociatedValue(); |
0 |
3743 |
Value *Val = &IRP.getAssociatedValue(); |
0 |
| 3744 |
if (IRP.getPositionKind() != IRP_CALL_SITE_ARGUMENT) { |
0 |
3744 |
if (IRP.getPositionKind() != IRP_CALL_SITE_ARGUMENT) { |
0 |
| 3745 |
if (isa(Val)) |
0 |
3745 |
if (isa(Val)) |
0 |
| 3746 |
return true; |
0 |
3746 |
return true; |
0 |
| 3747 |
} else { |
--- |
3747 |
} else { |
--- |
| 3748 |
IgnoreSubsumingPositions = true; |
0 |
3748 |
IgnoreSubsumingPositions = true; |
0 |
| 3749 |
} |
--- |
3749 |
} |
--- |
| 3750 |
|
--- |
3750 |
|
--- |
| 3751 |
if (isa(Val)) |
0 |
3751 |
if (isa(Val)) |
0 |
| 3752 |
return true; |
0 |
3752 |
return true; |
0 |
| 3753 |
|
--- |
3753 |
|
--- |
| 3754 |
if (isa(Val) && |
0 |
3754 |
if (isa(Val) && |
0 |
| 3755 |
!NullPointerIsDefined(IRP.getAnchorScope(), |
0 |
3755 |
!NullPointerIsDefined(IRP.getAnchorScope(), |
0 |
| 3756 |
Val->getType()->getPointerAddressSpace())) |
--- |
3756 |
Val->getType()->getPointerAddressSpace())) |
--- |
| 3757 |
return true; |
0 |
3757 |
return true; |
0 |
| 3758 |
|
--- |
3758 |
|
--- |
| 3759 |
if (A.hasAttr(IRP, {Attribute::ByVal, Attribute::NoAlias}, |
0 |
3759 |
if (A.hasAttr(IRP, {Attribute::ByVal, Attribute::NoAlias}, |
0 |
| 3760 |
IgnoreSubsumingPositions, Attribute::NoAlias)) |
--- |
3760 |
IgnoreSubsumingPositions, Attribute::NoAlias)) |
--- |
| 3761 |
return true; |
0 |
3761 |
return true; |
0 |
| 3762 |
|
--- |
3762 |
|
--- |
| 3763 |
return false; |
0 |
3763 |
return false; |
0 |
| 3764 |
} |
--- |
3764 |
} |
--- |
| 3765 |
|
--- |
3765 |
|
--- |
| 3766 |
namespace { |
--- |
3766 |
namespace { |
--- |
| 3767 |
struct AANoAliasImpl : AANoAlias { |
--- |
3767 |
struct AANoAliasImpl : AANoAlias { |
--- |
| 3768 |
AANoAliasImpl(const IRPosition &IRP, Attributor &A) : AANoAlias(IRP, A) { |
0 |
3768 |
AANoAliasImpl(const IRPosition &IRP, Attributor &A) : AANoAlias(IRP, A) { |
0 |
| 3769 |
assert(getAssociatedType()->isPointerTy() && |
0 |
3769 |
assert(getAssociatedType()->isPointerTy() && |
0 |
| 3770 |
"Noalias is a pointer attribute"); |
--- |
3770 |
"Noalias is a pointer attribute"); |
--- |
| 3771 |
} |
0 |
3771 |
} |
0 |
| 3772 |
|
--- |
3772 |
|
--- |
| 3773 |
const std::string getAsStr(Attributor *A) const override { |
0 |
3773 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 3774 |
return getAssumed() ? "noalias" : "may-alias"; |
0 |
3774 |
return getAssumed() ? "noalias" : "may-alias"; |
0 |
| 3775 |
} |
--- |
3775 |
} |
--- |
| 3776 |
}; |
--- |
3776 |
}; |
--- |
| 3777 |
|
--- |
3777 |
|
--- |
| 3778 |
/// NoAlias attribute for a floating value. |
--- |
3778 |
/// NoAlias attribute for a floating value. |
--- |
| 3779 |
struct AANoAliasFloating final : AANoAliasImpl { |
--- |
3779 |
struct AANoAliasFloating final : AANoAliasImpl { |
--- |
| 3780 |
AANoAliasFloating(const IRPosition &IRP, Attributor &A) |
0 |
3780 |
AANoAliasFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 3781 |
: AANoAliasImpl(IRP, A) {} |
0 |
3781 |
: AANoAliasImpl(IRP, A) {} |
0 |
| 3782 |
|
--- |
3782 |
|
--- |
| 3783 |
/// See AbstractAttribute::updateImpl(...). |
--- |
3783 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 3784 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
3784 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 3785 |
// TODO: Implement this. |
--- |
3785 |
// TODO: Implement this. |
--- |
| 3786 |
return indicatePessimisticFixpoint(); |
0 |
3786 |
return indicatePessimisticFixpoint(); |
0 |
| 3787 |
} |
--- |
3787 |
} |
--- |
| 3788 |
|
--- |
3788 |
|
--- |
| 3789 |
/// See AbstractAttribute::trackStatistics() |
--- |
3789 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 3790 |
void trackStatistics() const override { |
0 |
3790 |
void trackStatistics() const override { |
0 |
| 3791 |
STATS_DECLTRACK_FLOATING_ATTR(noalias) |
0 |
3791 |
STATS_DECLTRACK_FLOATING_ATTR(noalias) |
0 |
| 3792 |
} |
0 |
3792 |
} |
0 |
| 3793 |
}; |
--- |
3793 |
}; |
--- |
| 3794 |
|
--- |
3794 |
|
--- |
| 3795 |
/// NoAlias attribute for an argument. |
--- |
3795 |
/// NoAlias attribute for an argument. |
--- |
| 3796 |
struct AANoAliasArgument final |
--- |
3796 |
struct AANoAliasArgument final |
--- |
| 3797 |
: AAArgumentFromCallSiteArguments
| --- |
3797 |
: AAArgumentFromCallSiteArguments
| --- |
| |
| 3798 |
AANoAlias::StateType, false, |
--- |
3798 |
AANoAlias::StateType, false, |
--- |
| 3799 |
Attribute::NoAlias> { |
--- |
3799 |
Attribute::NoAlias> { |
--- |
| 3800 |
using Base = AAArgumentFromCallSiteArguments
| --- |
3800 |
using Base = AAArgumentFromCallSiteArguments
| --- |
| |
| 3801 |
AANoAlias::StateType, false, |
--- |
3801 |
AANoAlias::StateType, false, |
--- |
| 3802 |
Attribute::NoAlias>; |
--- |
3802 |
Attribute::NoAlias>; |
--- |
| 3803 |
AANoAliasArgument(const IRPosition &IRP, Attributor &A) : Base(IRP, A) {} |
0 |
3803 |
AANoAliasArgument(const IRPosition &IRP, Attributor &A) : Base(IRP, A) {} |
0 |
| 3804 |
|
--- |
3804 |
|
--- |
| 3805 |
/// See AbstractAttribute::update(...). |
--- |
3805 |
/// See AbstractAttribute::update(...). |
--- |
| 3806 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
3806 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 3807 |
// We have to make sure no-alias on the argument does not break |
--- |
3807 |
// We have to make sure no-alias on the argument does not break |
--- |
| 3808 |
// synchronization when this is a callback argument, see also [1] below. |
--- |
3808 |
// synchronization when this is a callback argument, see also [1] below. |
--- |
| 3809 |
// If synchronization cannot be affected, we delegate to the base updateImpl |
--- |
3809 |
// If synchronization cannot be affected, we delegate to the base updateImpl |
--- |
| 3810 |
// function, otherwise we give up for now. |
--- |
3810 |
// function, otherwise we give up for now. |
--- |
| 3811 |
|
--- |
3811 |
|
--- |
| 3812 |
// If the function is no-sync, no-alias cannot break synchronization. |
--- |
3812 |
// If the function is no-sync, no-alias cannot break synchronization. |
--- |
| 3813 |
bool IsKnownNoSycn; |
--- |
3813 |
bool IsKnownNoSycn; |
--- |
| 3814 |
if (AA::hasAssumedIRAttr( |
0 |
3814 |
if (AA::hasAssumedIRAttr( |
0 |
| 3815 |
A, this, IRPosition::function_scope(getIRPosition()), |
0 |
3815 |
A, this, IRPosition::function_scope(getIRPosition()), |
0 |
| 3816 |
DepClassTy::OPTIONAL, IsKnownNoSycn)) |
--- |
3816 |
DepClassTy::OPTIONAL, IsKnownNoSycn)) |
--- |
| 3817 |
return Base::updateImpl(A); |
0 |
3817 |
return Base::updateImpl(A); |
0 |
| 3818 |
|
--- |
3818 |
|
--- |
| 3819 |
// If the argument is read-only, no-alias cannot break synchronization. |
--- |
3819 |
// If the argument is read-only, no-alias cannot break synchronization. |
--- |
| 3820 |
bool IsKnown; |
--- |
3820 |
bool IsKnown; |
--- |
| 3821 |
if (AA::isAssumedReadOnly(A, getIRPosition(), *this, IsKnown)) |
0 |
3821 |
if (AA::isAssumedReadOnly(A, getIRPosition(), *this, IsKnown)) |
0 |
| 3822 |
return Base::updateImpl(A); |
0 |
3822 |
return Base::updateImpl(A); |
0 |
| 3823 |
|
--- |
3823 |
|
--- |
| 3824 |
// If the argument is never passed through callbacks, no-alias cannot break |
--- |
3824 |
// If the argument is never passed through callbacks, no-alias cannot break |
--- |
| 3825 |
// synchronization. |
--- |
3825 |
// synchronization. |
--- |
| 3826 |
bool UsedAssumedInformation = false; |
0 |
3826 |
bool UsedAssumedInformation = false; |
0 |
| 3827 |
if (A.checkForAllCallSites( |
0 |
3827 |
if (A.checkForAllCallSites( |
0 |
| 3828 |
[](AbstractCallSite ACS) { return !ACS.isCallbackCall(); }, *this, |
0 |
3828 |
[](AbstractCallSite ACS) { return !ACS.isCallbackCall(); }, *this, |
0 |
| 3829 |
true, UsedAssumedInformation)) |
--- |
3829 |
true, UsedAssumedInformation)) |
--- |
| 3830 |
return Base::updateImpl(A); |
0 |
3830 |
return Base::updateImpl(A); |
0 |
| 3831 |
|
--- |
3831 |
|
--- |
| 3832 |
// TODO: add no-alias but make sure it doesn't break synchronization by |
--- |
3832 |
// TODO: add no-alias but make sure it doesn't break synchronization by |
--- |
| 3833 |
// introducing fake uses. See: |
--- |
3833 |
// introducing fake uses. See: |
--- |
| 3834 |
// [1] Compiler Optimizations for OpenMP, J. Doerfert and H. Finkel, |
--- |
3834 |
// [1] Compiler Optimizations for OpenMP, J. Doerfert and H. Finkel, |
--- |
| 3835 |
// International Workshop on OpenMP 2018, |
--- |
3835 |
// International Workshop on OpenMP 2018, |
--- |
| 3836 |
// http://compilers.cs.uni-saarland.de/people/doerfert/par_opt18.pdf |
--- |
3836 |
// http://compilers.cs.uni-saarland.de/people/doerfert/par_opt18.pdf |
--- |
| 3837 |
|
--- |
3837 |
|
--- |
| 3838 |
return indicatePessimisticFixpoint(); |
0 |
3838 |
return indicatePessimisticFixpoint(); |
0 |
| 3839 |
} |
--- |
3839 |
} |
--- |
| 3840 |
|
--- |
3840 |
|
--- |
| 3841 |
/// See AbstractAttribute::trackStatistics() |
--- |
3841 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 3842 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(noalias) } |
0 |
3842 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(noalias) } |
0 |
| 3843 |
}; |
--- |
3843 |
}; |
--- |
| 3844 |
|
--- |
3844 |
|
--- |
| 3845 |
struct AANoAliasCallSiteArgument final : AANoAliasImpl { |
--- |
3845 |
struct AANoAliasCallSiteArgument final : AANoAliasImpl { |
--- |
| 3846 |
AANoAliasCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
3846 |
AANoAliasCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 3847 |
: AANoAliasImpl(IRP, A) {} |
0 |
3847 |
: AANoAliasImpl(IRP, A) {} |
0 |
| 3848 |
|
--- |
3848 |
|
--- |
| 3849 |
/// Determine if the underlying value may alias with the call site argument |
--- |
3849 |
/// Determine if the underlying value may alias with the call site argument |
--- |
| 3850 |
/// \p OtherArgNo of \p ICS (= the underlying call site). |
--- |
3850 |
/// \p OtherArgNo of \p ICS (= the underlying call site). |
--- |
| 3851 |
bool mayAliasWithArgument(Attributor &A, AAResults *&AAR, |
0 |
3851 |
bool mayAliasWithArgument(Attributor &A, AAResults *&AAR, |
0 |
| 3852 |
const AAMemoryBehavior &MemBehaviorAA, |
--- |
3852 |
const AAMemoryBehavior &MemBehaviorAA, |
--- |
| 3853 |
const CallBase &CB, unsigned OtherArgNo) { |
--- |
3853 |
const CallBase &CB, unsigned OtherArgNo) { |
--- |
| 3854 |
// We do not need to worry about aliasing with the underlying IRP. |
--- |
3854 |
// We do not need to worry about aliasing with the underlying IRP. |
--- |
| 3855 |
if (this->getCalleeArgNo() == (int)OtherArgNo) |
0 |
3855 |
if (this->getCalleeArgNo() == (int)OtherArgNo) |
0 |
| 3856 |
return false; |
0 |
3856 |
return false; |
0 |
| 3857 |
|
--- |
3857 |
|
--- |
| 3858 |
// If it is not a pointer or pointer vector we do not alias. |
--- |
3858 |
// If it is not a pointer or pointer vector we do not alias. |
--- |
| 3859 |
const Value *ArgOp = CB.getArgOperand(OtherArgNo); |
0 |
3859 |
const Value *ArgOp = CB.getArgOperand(OtherArgNo); |
0 |
| 3860 |
if (!ArgOp->getType()->isPtrOrPtrVectorTy()) |
0 |
3860 |
if (!ArgOp->getType()->isPtrOrPtrVectorTy()) |
0 |
| 3861 |
return false; |
0 |
3861 |
return false; |
0 |
| 3862 |
|
--- |
3862 |
|
--- |
| 3863 |
auto *CBArgMemBehaviorAA = A.getAAFor( |
0 |
3863 |
auto *CBArgMemBehaviorAA = A.getAAFor( |
0 |
| 3864 |
*this, IRPosition::callsite_argument(CB, OtherArgNo), DepClassTy::NONE); |
0 |
3864 |
*this, IRPosition::callsite_argument(CB, OtherArgNo), DepClassTy::NONE); |
0 |
| 3865 |
|
--- |
3865 |
|
--- |
| 3866 |
// If the argument is readnone, there is no read-write aliasing. |
--- |
3866 |
// If the argument is readnone, there is no read-write aliasing. |
--- |
| 3867 |
if (CBArgMemBehaviorAA && CBArgMemBehaviorAA->isAssumedReadNone()) { |
0 |
3867 |
if (CBArgMemBehaviorAA && CBArgMemBehaviorAA->isAssumedReadNone()) { |
0 |
| 3868 |
A.recordDependence(*CBArgMemBehaviorAA, *this, DepClassTy::OPTIONAL); |
0 |
3868 |
A.recordDependence(*CBArgMemBehaviorAA, *this, DepClassTy::OPTIONAL); |
0 |
| 3869 |
return false; |
0 |
3869 |
return false; |
0 |
| 3870 |
} |
--- |
3870 |
} |
--- |
| 3871 |
|
--- |
3871 |
|
--- |
| 3872 |
// If the argument is readonly and the underlying value is readonly, there |
--- |
3872 |
// If the argument is readonly and the underlying value is readonly, there |
--- |
| 3873 |
// is no read-write aliasing. |
--- |
3873 |
// is no read-write aliasing. |
--- |
| 3874 |
bool IsReadOnly = MemBehaviorAA.isAssumedReadOnly(); |
0 |
3874 |
bool IsReadOnly = MemBehaviorAA.isAssumedReadOnly(); |
0 |
| 3875 |
if (CBArgMemBehaviorAA && CBArgMemBehaviorAA->isAssumedReadOnly() && |
0 |
3875 |
if (CBArgMemBehaviorAA && CBArgMemBehaviorAA->isAssumedReadOnly() && |
0 |
| 3876 |
IsReadOnly) { |
--- |
3876 |
IsReadOnly) { |
--- |
| 3877 |
A.recordDependence(MemBehaviorAA, *this, DepClassTy::OPTIONAL); |
0 |
3877 |
A.recordDependence(MemBehaviorAA, *this, DepClassTy::OPTIONAL); |
0 |
| 3878 |
A.recordDependence(*CBArgMemBehaviorAA, *this, DepClassTy::OPTIONAL); |
0 |
3878 |
A.recordDependence(*CBArgMemBehaviorAA, *this, DepClassTy::OPTIONAL); |
0 |
| 3879 |
return false; |
0 |
3879 |
return false; |
0 |
| 3880 |
} |
--- |
3880 |
} |
--- |
| 3881 |
|
--- |
3881 |
|
--- |
| 3882 |
// We have to utilize actual alias analysis queries so we need the object. |
--- |
3882 |
// We have to utilize actual alias analysis queries so we need the object. |
--- |
| 3883 |
if (!AAR) |
0 |
3883 |
if (!AAR) |
0 |
| 3884 |
AAR = A.getInfoCache().getAnalysisResultForFunction( |
0 |
3884 |
AAR = A.getInfoCache().getAnalysisResultForFunction( |
0 |
| 3885 |
*getAnchorScope()); |
0 |
3885 |
*getAnchorScope()); |
0 |
| 3886 |
|
--- |
3886 |
|
--- |
| 3887 |
// Try to rule it out at the call site. |
--- |
3887 |
// Try to rule it out at the call site. |
--- |
| 3888 |
bool IsAliasing = !AAR || !AAR->isNoAlias(&getAssociatedValue(), ArgOp); |
0 |
3888 |
bool IsAliasing = !AAR || !AAR->isNoAlias(&getAssociatedValue(), ArgOp); |
0 |
| 3889 |
LLVM_DEBUG(dbgs() << "[NoAliasCSArg] Check alias between " |
0 |
3889 |
LLVM_DEBUG(dbgs() << "[NoAliasCSArg] Check alias between " |
0 |
| 3890 |
"callsite arguments: " |
--- |
3890 |
"callsite arguments: " |
--- |
| 3891 |
<< getAssociatedValue() << " " << *ArgOp << " => " |
--- |
3891 |
<< getAssociatedValue() << " " << *ArgOp << " => " |
--- |
| 3892 |
<< (IsAliasing ? "" : "no-") << "alias \n"); |
--- |
3892 |
<< (IsAliasing ? "" : "no-") << "alias \n"); |
--- |
| 3893 |
|
--- |
3893 |
|
--- |
| 3894 |
return IsAliasing; |
0 |
3894 |
return IsAliasing; |
0 |
| 3895 |
} |
--- |
3895 |
} |
--- |
| 3896 |
|
--- |
3896 |
|
--- |
| 3897 |
bool isKnownNoAliasDueToNoAliasPreservation( |
0 |
3897 |
bool isKnownNoAliasDueToNoAliasPreservation( |
0 |
| 3898 |
Attributor &A, AAResults *&AAR, const AAMemoryBehavior &MemBehaviorAA) { |
--- |
3898 |
Attributor &A, AAResults *&AAR, const AAMemoryBehavior &MemBehaviorAA) { |
--- |
| 3899 |
// We can deduce "noalias" if the following conditions hold. |
--- |
3899 |
// We can deduce "noalias" if the following conditions hold. |
--- |
| 3900 |
// (i) Associated value is assumed to be noalias in the definition. |
--- |
3900 |
// (i) Associated value is assumed to be noalias in the definition. |
--- |
| 3901 |
// (ii) Associated value is assumed to be no-capture in all the uses |
--- |
3901 |
// (ii) Associated value is assumed to be no-capture in all the uses |
--- |
| 3902 |
// possibly executed before this callsite. |
--- |
3902 |
// possibly executed before this callsite. |
--- |
| 3903 |
// (iii) There is no other pointer argument which could alias with the |
--- |
3903 |
// (iii) There is no other pointer argument which could alias with the |
--- |
| 3904 |
// value. |
--- |
3904 |
// value. |
--- |
| 3905 |
|
--- |
3905 |
|
--- |
| 3906 |
auto IsDereferenceableOrNull = [&](Value *O, const DataLayout &DL) { |
0 |
3906 |
auto IsDereferenceableOrNull = [&](Value *O, const DataLayout &DL) { |
0 |
| 3907 |
const auto *DerefAA = A.getAAFor( |
0 |
3907 |
const auto *DerefAA = A.getAAFor( |
0 |
| 3908 |
*this, IRPosition::value(*O), DepClassTy::OPTIONAL); |
0 |
3908 |
*this, IRPosition::value(*O), DepClassTy::OPTIONAL); |
0 |
| 3909 |
return DerefAA ? DerefAA->getAssumedDereferenceableBytes() : 0; |
0 |
3909 |
return DerefAA ? DerefAA->getAssumedDereferenceableBytes() : 0; |
0 |
| 3910 |
}; |
0 |
3910 |
}; |
0 |
| 3911 |
|
--- |
3911 |
|
--- |
| 3912 |
const IRPosition &VIRP = IRPosition::value(getAssociatedValue()); |
0 |
3912 |
const IRPosition &VIRP = IRPosition::value(getAssociatedValue()); |
0 |
| 3913 |
const Function *ScopeFn = VIRP.getAnchorScope(); |
0 |
3913 |
const Function *ScopeFn = VIRP.getAnchorScope(); |
0 |
| 3914 |
// Check whether the value is captured in the scope using AANoCapture. |
--- |
3914 |
// Check whether the value is captured in the scope using AANoCapture. |
--- |
| 3915 |
// Look at CFG and check only uses possibly executed before this |
--- |
3915 |
// Look at CFG and check only uses possibly executed before this |
--- |
| 3916 |
// callsite. |
--- |
3916 |
// callsite. |
--- |
| 3917 |
auto UsePred = [&](const Use &U, bool &Follow) -> bool { |
0 |
3917 |
auto UsePred = [&](const Use &U, bool &Follow) -> bool { |
0 |
| 3918 |
Instruction *UserI = cast(U.getUser()); |
0 |
3918 |
Instruction *UserI = cast(U.getUser()); |
0 |
| 3919 |
|
--- |
3919 |
|
--- |
| 3920 |
// If UserI is the curr instruction and there is a single potential use of |
--- |
3920 |
// If UserI is the curr instruction and there is a single potential use of |
--- |
| 3921 |
// the value in UserI we allow the use. |
--- |
3921 |
// the value in UserI we allow the use. |
--- |
| 3922 |
// TODO: We should inspect the operands and allow those that cannot alias |
--- |
3922 |
// TODO: We should inspect the operands and allow those that cannot alias |
--- |
| 3923 |
// with the value. |
--- |
3923 |
// with the value. |
--- |
| 3924 |
if (UserI == getCtxI() && UserI->getNumOperands() == 1) |
0 |
3924 |
if (UserI == getCtxI() && UserI->getNumOperands() == 1) |
0 |
| 3925 |
return true; |
0 |
3925 |
return true; |
0 |
| 3926 |
|
--- |
3926 |
|
--- |
| 3927 |
if (ScopeFn) { |
0 |
3927 |
if (ScopeFn) { |
0 |
| 3928 |
if (auto *CB = dyn_cast(UserI)) { |
0 |
3928 |
if (auto *CB = dyn_cast(UserI)) { |
0 |
| 3929 |
if (CB->isArgOperand(&U)) { |
0 |
3929 |
if (CB->isArgOperand(&U)) { |
0 |
| 3930 |
|
--- |
3930 |
|
--- |
| 3931 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
3931 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
| 3932 |
|
--- |
3932 |
|
--- |
| 3933 |
bool IsKnownNoCapture; |
--- |
3933 |
bool IsKnownNoCapture; |
--- |
| 3934 |
if (AA::hasAssumedIRAttr( |
0 |
3934 |
if (AA::hasAssumedIRAttr( |
0 |
| 3935 |
A, this, IRPosition::callsite_argument(*CB, ArgNo), |
0 |
3935 |
A, this, IRPosition::callsite_argument(*CB, ArgNo), |
0 |
| 3936 |
DepClassTy::OPTIONAL, IsKnownNoCapture)) |
--- |
3936 |
DepClassTy::OPTIONAL, IsKnownNoCapture)) |
--- |
| 3937 |
return true; |
0 |
3937 |
return true; |
0 |
| 3938 |
} |
--- |
3938 |
} |
--- |
| 3939 |
} |
--- |
3939 |
} |
--- |
| 3940 |
|
--- |
3940 |
|
--- |
| 3941 |
if (!AA::isPotentiallyReachable( |
0 |
3941 |
if (!AA::isPotentiallyReachable( |
0 |
| 3942 |
A, *UserI, *getCtxI(), *this, /* ExclusionSet */ nullptr, |
0 |
3942 |
A, *UserI, *getCtxI(), *this, /* ExclusionSet */ nullptr, |
0 |
| 3943 |
[ScopeFn](const Function &Fn) { return &Fn != ScopeFn; })) |
0 |
3943 |
[ScopeFn](const Function &Fn) { return &Fn != ScopeFn; })) |
0 |
| 3944 |
return true; |
0 |
3944 |
return true; |
0 |
| 3945 |
} |
--- |
3945 |
} |
--- |
| 3946 |
|
--- |
3946 |
|
--- |
| 3947 |
// TODO: We should track the capturing uses in AANoCapture but the problem |
--- |
3947 |
// TODO: We should track the capturing uses in AANoCapture but the problem |
--- |
| 3948 |
// is CGSCC runs. For those we would need to "allow" AANoCapture for |
--- |
3948 |
// is CGSCC runs. For those we would need to "allow" AANoCapture for |
--- |
| 3949 |
// a value in the module slice. |
--- |
3949 |
// a value in the module slice. |
--- |
| 3950 |
switch (DetermineUseCaptureKind(U, IsDereferenceableOrNull)) { |
0 |
3950 |
switch (DetermineUseCaptureKind(U, IsDereferenceableOrNull)) { |
0 |
| 3951 |
case UseCaptureKind::NO_CAPTURE: |
0 |
3951 |
case UseCaptureKind::NO_CAPTURE: |
0 |
| 3952 |
return true; |
0 |
3952 |
return true; |
0 |
| 3953 |
case UseCaptureKind::MAY_CAPTURE: |
0 |
3953 |
case UseCaptureKind::MAY_CAPTURE: |
0 |
| 3954 |
LLVM_DEBUG(dbgs() << "[AANoAliasCSArg] Unknown user: " << *UserI |
0 |
3954 |
LLVM_DEBUG(dbgs() << "[AANoAliasCSArg] Unknown user: " << *UserI |
0 |
| 3955 |
<< "\n"); |
--- |
3955 |
<< "\n"); |
--- |
| 3956 |
return false; |
0 |
3956 |
return false; |
0 |
| 3957 |
case UseCaptureKind::PASSTHROUGH: |
0 |
3957 |
case UseCaptureKind::PASSTHROUGH: |
0 |
| 3958 |
Follow = true; |
0 |
3958 |
Follow = true; |
0 |
| 3959 |
return true; |
0 |
3959 |
return true; |
0 |
| 3960 |
} |
--- |
3960 |
} |
--- |
| 3961 |
llvm_unreachable("unknown UseCaptureKind"); |
0 |
3961 |
llvm_unreachable("unknown UseCaptureKind"); |
0 |
| 3962 |
}; |
0 |
3962 |
}; |
0 |
| 3963 |
|
--- |
3963 |
|
--- |
| 3964 |
bool IsKnownNoCapture; |
--- |
3964 |
bool IsKnownNoCapture; |
--- |
| 3965 |
const AANoCapture *NoCaptureAA = nullptr; |
0 |
3965 |
const AANoCapture *NoCaptureAA = nullptr; |
0 |
| 3966 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
3966 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
| 3967 |
A, this, VIRP, DepClassTy::NONE, IsKnownNoCapture, false, &NoCaptureAA); |
--- |
3967 |
A, this, VIRP, DepClassTy::NONE, IsKnownNoCapture, false, &NoCaptureAA); |
--- |
| 3968 |
if (!IsAssumedNoCapture && |
0 |
3968 |
if (!IsAssumedNoCapture && |
0 |
| 3969 |
(!NoCaptureAA || !NoCaptureAA->isAssumedNoCaptureMaybeReturned())) { |
0 |
3969 |
(!NoCaptureAA || !NoCaptureAA->isAssumedNoCaptureMaybeReturned())) { |
0 |
| 3970 |
if (!A.checkForAllUses(UsePred, *this, getAssociatedValue())) { |
0 |
3970 |
if (!A.checkForAllUses(UsePred, *this, getAssociatedValue())) { |
0 |
| 3971 |
LLVM_DEBUG( |
0 |
3971 |
LLVM_DEBUG( |
0 |
| 3972 |
dbgs() << "[AANoAliasCSArg] " << getAssociatedValue() |
--- |
3972 |
dbgs() << "[AANoAliasCSArg] " << getAssociatedValue() |
--- |
| 3973 |
<< " cannot be noalias as it is potentially captured\n"); |
--- |
3973 |
<< " cannot be noalias as it is potentially captured\n"); |
--- |
| 3974 |
return false; |
0 |
3974 |
return false; |
0 |
| 3975 |
} |
--- |
3975 |
} |
--- |
| 3976 |
} |
--- |
3976 |
} |
--- |
| 3977 |
if (NoCaptureAA) |
0 |
3977 |
if (NoCaptureAA) |
0 |
| 3978 |
A.recordDependence(*NoCaptureAA, *this, DepClassTy::OPTIONAL); |
0 |
3978 |
A.recordDependence(*NoCaptureAA, *this, DepClassTy::OPTIONAL); |
0 |
| 3979 |
|
--- |
3979 |
|
--- |
| 3980 |
// Check there is no other pointer argument which could alias with the |
--- |
3980 |
// Check there is no other pointer argument which could alias with the |
--- |
| 3981 |
// value passed at this call site. |
--- |
3981 |
// value passed at this call site. |
--- |
| 3982 |
// TODO: AbstractCallSite |
--- |
3982 |
// TODO: AbstractCallSite |
--- |
| 3983 |
const auto &CB = cast(getAnchorValue()); |
0 |
3983 |
const auto &CB = cast(getAnchorValue()); |
0 |
| 3984 |
for (unsigned OtherArgNo = 0; OtherArgNo < CB.arg_size(); OtherArgNo++) |
0 |
3984 |
for (unsigned OtherArgNo = 0; OtherArgNo < CB.arg_size(); OtherArgNo++) |
0 |
| 3985 |
if (mayAliasWithArgument(A, AAR, MemBehaviorAA, CB, OtherArgNo)) |
0 |
3985 |
if (mayAliasWithArgument(A, AAR, MemBehaviorAA, CB, OtherArgNo)) |
0 |
| 3986 |
return false; |
0 |
3986 |
return false; |
0 |
| 3987 |
|
--- |
3987 |
|
--- |
| 3988 |
return true; |
0 |
3988 |
return true; |
0 |
| 3989 |
} |
--- |
3989 |
} |
--- |
| 3990 |
|
--- |
3990 |
|
--- |
| 3991 |
/// See AbstractAttribute::updateImpl(...). |
--- |
3991 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 3992 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
3992 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 3993 |
// If the argument is readnone we are done as there are no accesses via the |
--- |
3993 |
// If the argument is readnone we are done as there are no accesses via the |
--- |
| 3994 |
// argument. |
--- |
3994 |
// argument. |
--- |
| 3995 |
auto *MemBehaviorAA = |
--- |
3995 |
auto *MemBehaviorAA = |
--- |
| 3996 |
A.getAAFor(*this, getIRPosition(), DepClassTy::NONE); |
0 |
3996 |
A.getAAFor(*this, getIRPosition(), DepClassTy::NONE); |
0 |
| 3997 |
if (MemBehaviorAA && MemBehaviorAA->isAssumedReadNone()) { |
0 |
3997 |
if (MemBehaviorAA && MemBehaviorAA->isAssumedReadNone()) { |
0 |
| 3998 |
A.recordDependence(*MemBehaviorAA, *this, DepClassTy::OPTIONAL); |
0 |
3998 |
A.recordDependence(*MemBehaviorAA, *this, DepClassTy::OPTIONAL); |
0 |
| 3999 |
return ChangeStatus::UNCHANGED; |
0 |
3999 |
return ChangeStatus::UNCHANGED; |
0 |
| 4000 |
} |
--- |
4000 |
} |
--- |
| 4001 |
|
--- |
4001 |
|
--- |
| 4002 |
bool IsKnownNoAlias; |
--- |
4002 |
bool IsKnownNoAlias; |
--- |
| 4003 |
const IRPosition &VIRP = IRPosition::value(getAssociatedValue()); |
0 |
4003 |
const IRPosition &VIRP = IRPosition::value(getAssociatedValue()); |
0 |
| 4004 |
if (!AA::hasAssumedIRAttr( |
0 |
4004 |
if (!AA::hasAssumedIRAttr( |
0 |
| 4005 |
A, this, VIRP, DepClassTy::REQUIRED, IsKnownNoAlias)) { |
--- |
4005 |
A, this, VIRP, DepClassTy::REQUIRED, IsKnownNoAlias)) { |
--- |
| 4006 |
LLVM_DEBUG(dbgs() << "[AANoAlias] " << getAssociatedValue() |
0 |
4006 |
LLVM_DEBUG(dbgs() << "[AANoAlias] " << getAssociatedValue() |
0 |
| 4007 |
<< " is not no-alias at the definition\n"); |
--- |
4007 |
<< " is not no-alias at the definition\n"); |
--- |
| 4008 |
return indicatePessimisticFixpoint(); |
0 |
4008 |
return indicatePessimisticFixpoint(); |
0 |
| 4009 |
} |
--- |
4009 |
} |
--- |
| 4010 |
|
--- |
4010 |
|
--- |
| 4011 |
AAResults *AAR = nullptr; |
0 |
4011 |
AAResults *AAR = nullptr; |
0 |
| 4012 |
if (MemBehaviorAA && |
0 |
4012 |
if (MemBehaviorAA && |
0 |
| 4013 |
isKnownNoAliasDueToNoAliasPreservation(A, AAR, *MemBehaviorAA)) { |
0 |
4013 |
isKnownNoAliasDueToNoAliasPreservation(A, AAR, *MemBehaviorAA)) { |
0 |
| 4014 |
LLVM_DEBUG( |
0 |
4014 |
LLVM_DEBUG( |
0 |
| 4015 |
dbgs() << "[AANoAlias] No-Alias deduced via no-alias preservation\n"); |
--- |
4015 |
dbgs() << "[AANoAlias] No-Alias deduced via no-alias preservation\n"); |
--- |
| 4016 |
return ChangeStatus::UNCHANGED; |
0 |
4016 |
return ChangeStatus::UNCHANGED; |
0 |
| 4017 |
} |
--- |
4017 |
} |
--- |
| 4018 |
|
--- |
4018 |
|
--- |
| 4019 |
return indicatePessimisticFixpoint(); |
0 |
4019 |
return indicatePessimisticFixpoint(); |
0 |
| 4020 |
} |
--- |
4020 |
} |
--- |
| 4021 |
|
--- |
4021 |
|
--- |
| 4022 |
/// See AbstractAttribute::trackStatistics() |
--- |
4022 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 4023 |
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(noalias) } |
0 |
4023 |
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(noalias) } |
0 |
| 4024 |
}; |
--- |
4024 |
}; |
--- |
| 4025 |
|
--- |
4025 |
|
--- |
| 4026 |
/// NoAlias attribute for function return value. |
--- |
4026 |
/// NoAlias attribute for function return value. |
--- |
| 4027 |
struct AANoAliasReturned final : AANoAliasImpl { |
--- |
4027 |
struct AANoAliasReturned final : AANoAliasImpl { |
--- |
| 4028 |
AANoAliasReturned(const IRPosition &IRP, Attributor &A) |
0 |
4028 |
AANoAliasReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 4029 |
: AANoAliasImpl(IRP, A) {} |
0 |
4029 |
: AANoAliasImpl(IRP, A) {} |
0 |
| 4030 |
|
--- |
4030 |
|
--- |
| 4031 |
/// See AbstractAttribute::updateImpl(...). |
--- |
4031 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 4032 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
4032 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 4033 |
|
--- |
4033 |
|
--- |
| 4034 |
auto CheckReturnValue = [&](Value &RV) -> bool { |
0 |
4034 |
auto CheckReturnValue = [&](Value &RV) -> bool { |
0 |
| 4035 |
if (Constant *C = dyn_cast(&RV)) |
0 |
4035 |
if (Constant *C = dyn_cast(&RV)) |
0 |
| 4036 |
if (C->isNullValue() || isa(C)) |
0 |
4036 |
if (C->isNullValue() || isa(C)) |
0 |
| 4037 |
return true; |
0 |
4037 |
return true; |
0 |
| 4038 |
|
--- |
4038 |
|
--- |
| 4039 |
/// For now, we can only deduce noalias if we have call sites. |
--- |
4039 |
/// For now, we can only deduce noalias if we have call sites. |
--- |
| 4040 |
/// FIXME: add more support. |
--- |
4040 |
/// FIXME: add more support. |
--- |
| 4041 |
if (!isa(&RV)) |
0 |
4041 |
if (!isa(&RV)) |
0 |
| 4042 |
return false; |
0 |
4042 |
return false; |
0 |
| 4043 |
|
--- |
4043 |
|
--- |
| 4044 |
const IRPosition &RVPos = IRPosition::value(RV); |
0 |
4044 |
const IRPosition &RVPos = IRPosition::value(RV); |
0 |
| 4045 |
bool IsKnownNoAlias; |
--- |
4045 |
bool IsKnownNoAlias; |
--- |
| 4046 |
if (!AA::hasAssumedIRAttr( |
0 |
4046 |
if (!AA::hasAssumedIRAttr( |
0 |
| 4047 |
A, this, RVPos, DepClassTy::REQUIRED, IsKnownNoAlias)) |
0 |
4047 |
A, this, RVPos, DepClassTy::REQUIRED, IsKnownNoAlias)) |
0 |
| 4048 |
return false; |
0 |
4048 |
return false; |
0 |
| 4049 |
|
--- |
4049 |
|
--- |
| 4050 |
bool IsKnownNoCapture; |
--- |
4050 |
bool IsKnownNoCapture; |
--- |
| 4051 |
const AANoCapture *NoCaptureAA = nullptr; |
0 |
4051 |
const AANoCapture *NoCaptureAA = nullptr; |
0 |
| 4052 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
4052 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
| 4053 |
A, this, RVPos, DepClassTy::REQUIRED, IsKnownNoCapture, false, |
--- |
4053 |
A, this, RVPos, DepClassTy::REQUIRED, IsKnownNoCapture, false, |
--- |
| 4054 |
&NoCaptureAA); |
--- |
4054 |
&NoCaptureAA); |
--- |
| 4055 |
return IsAssumedNoCapture || |
0 |
4055 |
return IsAssumedNoCapture || |
0 |
| 4056 |
(NoCaptureAA && NoCaptureAA->isAssumedNoCaptureMaybeReturned()); |
0 |
4056 |
(NoCaptureAA && NoCaptureAA->isAssumedNoCaptureMaybeReturned()); |
0 |
| 4057 |
}; |
0 |
4057 |
}; |
0 |
| 4058 |
|
--- |
4058 |
|
--- |
| 4059 |
if (!A.checkForAllReturnedValues(CheckReturnValue, *this)) |
0 |
4059 |
if (!A.checkForAllReturnedValues(CheckReturnValue, *this)) |
0 |
| 4060 |
return indicatePessimisticFixpoint(); |
0 |
4060 |
return indicatePessimisticFixpoint(); |
0 |
| 4061 |
|
--- |
4061 |
|
--- |
| 4062 |
return ChangeStatus::UNCHANGED; |
0 |
4062 |
return ChangeStatus::UNCHANGED; |
0 |
| 4063 |
} |
--- |
4063 |
} |
--- |
| 4064 |
|
--- |
4064 |
|
--- |
| 4065 |
/// See AbstractAttribute::trackStatistics() |
--- |
4065 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 4066 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(noalias) } |
0 |
4066 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(noalias) } |
0 |
| 4067 |
}; |
--- |
4067 |
}; |
--- |
| 4068 |
|
--- |
4068 |
|
--- |
| 4069 |
/// NoAlias attribute deduction for a call site return value. |
--- |
4069 |
/// NoAlias attribute deduction for a call site return value. |
--- |
| 4070 |
struct AANoAliasCallSiteReturned final : AANoAliasImpl { |
--- |
4070 |
struct AANoAliasCallSiteReturned final : AANoAliasImpl { |
--- |
| 4071 |
AANoAliasCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
4071 |
AANoAliasCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 4072 |
: AANoAliasImpl(IRP, A) {} |
0 |
4072 |
: AANoAliasImpl(IRP, A) {} |
0 |
| 4073 |
|
--- |
4073 |
|
--- |
| 4074 |
/// See AbstractAttribute::updateImpl(...). |
--- |
4074 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 4075 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
4075 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 4076 |
// TODO: Once we have call site specific value information we can provide |
--- |
4076 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 4077 |
// call site specific liveness information and then it makes |
--- |
4077 |
// call site specific liveness information and then it makes |
--- |
| 4078 |
// sense to specialize attributes for call sites arguments instead of |
--- |
4078 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 4079 |
// redirecting requests to the callee argument. |
--- |
4079 |
// redirecting requests to the callee argument. |
--- |
| 4080 |
Function *F = getAssociatedFunction(); |
0 |
4080 |
Function *F = getAssociatedFunction(); |
0 |
| 4081 |
const IRPosition &FnPos = IRPosition::returned(*F); |
0 |
4081 |
const IRPosition &FnPos = IRPosition::returned(*F); |
0 |
| 4082 |
bool IsKnownNoAlias; |
--- |
4082 |
bool IsKnownNoAlias; |
--- |
| 4083 |
if (!AA::hasAssumedIRAttr( |
0 |
4083 |
if (!AA::hasAssumedIRAttr( |
0 |
| 4084 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownNoAlias)) |
--- |
4084 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownNoAlias)) |
--- |
| 4085 |
return indicatePessimisticFixpoint(); |
0 |
4085 |
return indicatePessimisticFixpoint(); |
0 |
| 4086 |
return ChangeStatus::UNCHANGED; |
0 |
4086 |
return ChangeStatus::UNCHANGED; |
0 |
| 4087 |
} |
--- |
4087 |
} |
--- |
| 4088 |
|
--- |
4088 |
|
--- |
| 4089 |
/// See AbstractAttribute::trackStatistics() |
--- |
4089 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 4090 |
void trackStatistics() const override { STATS_DECLTRACK_CSRET_ATTR(noalias); } |
0 |
4090 |
void trackStatistics() const override { STATS_DECLTRACK_CSRET_ATTR(noalias); } |
0 |
| 4091 |
}; |
--- |
4091 |
}; |
--- |
| 4092 |
} // namespace |
--- |
4092 |
} // namespace |
--- |
| 4093 |
|
--- |
4093 |
|
--- |
| 4094 |
/// -------------------AAIsDead Function Attribute----------------------- |
--- |
4094 |
/// -------------------AAIsDead Function Attribute----------------------- |
--- |
| 4095 |
|
--- |
4095 |
|
--- |
| 4096 |
namespace { |
--- |
4096 |
namespace { |
--- |
| 4097 |
struct AAIsDeadValueImpl : public AAIsDead { |
--- |
4097 |
struct AAIsDeadValueImpl : public AAIsDead { |
--- |
| 4098 |
AAIsDeadValueImpl(const IRPosition &IRP, Attributor &A) : AAIsDead(IRP, A) {} |
0 |
4098 |
AAIsDeadValueImpl(const IRPosition &IRP, Attributor &A) : AAIsDead(IRP, A) {} |
0 |
| 4099 |
|
--- |
4099 |
|
--- |
| 4100 |
/// See AAIsDead::isAssumedDead(). |
--- |
4100 |
/// See AAIsDead::isAssumedDead(). |
--- |
| 4101 |
bool isAssumedDead() const override { return isAssumed(IS_DEAD); } |
0 |
4101 |
bool isAssumedDead() const override { return isAssumed(IS_DEAD); } |
0 |
| 4102 |
|
--- |
4102 |
|
--- |
| 4103 |
/// See AAIsDead::isKnownDead(). |
--- |
4103 |
/// See AAIsDead::isKnownDead(). |
--- |
| 4104 |
bool isKnownDead() const override { return isKnown(IS_DEAD); } |
0 |
4104 |
bool isKnownDead() const override { return isKnown(IS_DEAD); } |
0 |
| 4105 |
|
--- |
4105 |
|
--- |
| 4106 |
/// See AAIsDead::isAssumedDead(BasicBlock *). |
--- |
4106 |
/// See AAIsDead::isAssumedDead(BasicBlock *). |
--- |
| 4107 |
bool isAssumedDead(const BasicBlock *BB) const override { return false; } |
0 |
4107 |
bool isAssumedDead(const BasicBlock *BB) const override { return false; } |
0 |
| 4108 |
|
--- |
4108 |
|
--- |
| 4109 |
/// See AAIsDead::isKnownDead(BasicBlock *). |
--- |
4109 |
/// See AAIsDead::isKnownDead(BasicBlock *). |
--- |
| 4110 |
bool isKnownDead(const BasicBlock *BB) const override { return false; } |
0 |
4110 |
bool isKnownDead(const BasicBlock *BB) const override { return false; } |
0 |
| 4111 |
|
--- |
4111 |
|
--- |
| 4112 |
/// See AAIsDead::isAssumedDead(Instruction *I). |
--- |
4112 |
/// See AAIsDead::isAssumedDead(Instruction *I). |
--- |
| 4113 |
bool isAssumedDead(const Instruction *I) const override { |
0 |
4113 |
bool isAssumedDead(const Instruction *I) const override { |
0 |
| 4114 |
return I == getCtxI() && isAssumedDead(); |
0 |
4114 |
return I == getCtxI() && isAssumedDead(); |
0 |
| 4115 |
} |
--- |
4115 |
} |
--- |
| 4116 |
|
--- |
4116 |
|
--- |
| 4117 |
/// See AAIsDead::isKnownDead(Instruction *I). |
--- |
4117 |
/// See AAIsDead::isKnownDead(Instruction *I). |
--- |
| 4118 |
bool isKnownDead(const Instruction *I) const override { |
0 |
4118 |
bool isKnownDead(const Instruction *I) const override { |
0 |
| 4119 |
return isAssumedDead(I) && isKnownDead(); |
0 |
4119 |
return isAssumedDead(I) && isKnownDead(); |
0 |
| 4120 |
} |
--- |
4120 |
} |
--- |
| 4121 |
|
--- |
4121 |
|
--- |
| 4122 |
/// See AbstractAttribute::getAsStr(). |
--- |
4122 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 4123 |
const std::string getAsStr(Attributor *A) const override { |
0 |
4123 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 4124 |
return isAssumedDead() ? "assumed-dead" : "assumed-live"; |
0 |
4124 |
return isAssumedDead() ? "assumed-dead" : "assumed-live"; |
0 |
| 4125 |
} |
--- |
4125 |
} |
--- |
| 4126 |
|
--- |
4126 |
|
--- |
| 4127 |
/// Check if all uses are assumed dead. |
--- |
4127 |
/// Check if all uses are assumed dead. |
--- |
| 4128 |
bool areAllUsesAssumedDead(Attributor &A, Value &V) { |
0 |
4128 |
bool areAllUsesAssumedDead(Attributor &A, Value &V) { |
0 |
| 4129 |
// Callers might not check the type, void has no uses. |
--- |
4129 |
// Callers might not check the type, void has no uses. |
--- |
| 4130 |
if (V.getType()->isVoidTy() || V.use_empty()) |
0 |
4130 |
if (V.getType()->isVoidTy() || V.use_empty()) |
0 |
| 4131 |
return true; |
0 |
4131 |
return true; |
0 |
| 4132 |
|
--- |
4132 |
|
--- |
| 4133 |
// If we replace a value with a constant there are no uses left afterwards. |
--- |
4133 |
// If we replace a value with a constant there are no uses left afterwards. |
--- |
| 4134 |
if (!isa(V)) { |
0 |
4134 |
if (!isa(V)) { |
0 |
| 4135 |
if (auto *I = dyn_cast(&V)) |
0 |
4135 |
if (auto *I = dyn_cast(&V)) |
0 |
| 4136 |
if (!A.isRunOn(*I->getFunction())) |
0 |
4136 |
if (!A.isRunOn(*I->getFunction())) |
0 |
| 4137 |
return false; |
0 |
4137 |
return false; |
0 |
| 4138 |
bool UsedAssumedInformation = false; |
0 |
4138 |
bool UsedAssumedInformation = false; |
0 |
| 4139 |
std::optional C = |
--- |
4139 |
std::optional C = |
--- |
| 4140 |
A.getAssumedConstant(V, *this, UsedAssumedInformation); |
0 |
4140 |
A.getAssumedConstant(V, *this, UsedAssumedInformation); |
0 |
| 4141 |
if (!C || *C) |
0 |
4141 |
if (!C || *C) |
0 |
| 4142 |
return true; |
0 |
4142 |
return true; |
0 |
| 4143 |
} |
--- |
4143 |
} |
--- |
| 4144 |
|
--- |
4144 |
|
--- |
| 4145 |
auto UsePred = [&](const Use &U, bool &Follow) { return false; }; |
0 |
4145 |
auto UsePred = [&](const Use &U, bool &Follow) { return false; }; |
0 |
| 4146 |
// Explicitly set the dependence class to required because we want a long |
--- |
4146 |
// Explicitly set the dependence class to required because we want a long |
--- |
| 4147 |
// chain of N dependent instructions to be considered live as soon as one is |
--- |
4147 |
// chain of N dependent instructions to be considered live as soon as one is |
--- |
| 4148 |
// without going through N update cycles. This is not required for |
--- |
4148 |
// without going through N update cycles. This is not required for |
--- |
| 4149 |
// correctness. |
--- |
4149 |
// correctness. |
--- |
| 4150 |
return A.checkForAllUses(UsePred, *this, V, /* CheckBBLivenessOnly */ false, |
0 |
4150 |
return A.checkForAllUses(UsePred, *this, V, /* CheckBBLivenessOnly */ false, |
0 |
| 4151 |
DepClassTy::REQUIRED, |
--- |
4151 |
DepClassTy::REQUIRED, |
--- |
| 4152 |
/* IgnoreDroppableUses */ false); |
0 |
4152 |
/* IgnoreDroppableUses */ false); |
0 |
| 4153 |
} |
--- |
4153 |
} |
--- |
| 4154 |
|
--- |
4154 |
|
--- |
| 4155 |
/// Determine if \p I is assumed to be side-effect free. |
--- |
4155 |
/// Determine if \p I is assumed to be side-effect free. |
--- |
| 4156 |
bool isAssumedSideEffectFree(Attributor &A, Instruction *I) { |
0 |
4156 |
bool isAssumedSideEffectFree(Attributor &A, Instruction *I) { |
0 |
| 4157 |
if (!I || wouldInstructionBeTriviallyDead(I)) |
0 |
4157 |
if (!I || wouldInstructionBeTriviallyDead(I)) |
0 |
| 4158 |
return true; |
0 |
4158 |
return true; |
0 |
| 4159 |
|
--- |
4159 |
|
--- |
| 4160 |
auto *CB = dyn_cast(I); |
0 |
4160 |
auto *CB = dyn_cast(I); |
0 |
| 4161 |
if (!CB || isa(CB)) |
0 |
4161 |
if (!CB || isa(CB)) |
0 |
| 4162 |
return false; |
0 |
4162 |
return false; |
0 |
| 4163 |
|
--- |
4163 |
|
--- |
| 4164 |
const IRPosition &CallIRP = IRPosition::callsite_function(*CB); |
0 |
4164 |
const IRPosition &CallIRP = IRPosition::callsite_function(*CB); |
0 |
| 4165 |
|
--- |
4165 |
|
--- |
| 4166 |
bool IsKnownNoUnwind; |
--- |
4166 |
bool IsKnownNoUnwind; |
--- |
| 4167 |
if (!AA::hasAssumedIRAttr( |
0 |
4167 |
if (!AA::hasAssumedIRAttr( |
0 |
| 4168 |
A, this, CallIRP, DepClassTy::OPTIONAL, IsKnownNoUnwind)) |
--- |
4168 |
A, this, CallIRP, DepClassTy::OPTIONAL, IsKnownNoUnwind)) |
--- |
| 4169 |
return false; |
0 |
4169 |
return false; |
0 |
| 4170 |
|
--- |
4170 |
|
--- |
| 4171 |
bool IsKnown; |
--- |
4171 |
bool IsKnown; |
--- |
| 4172 |
return AA::isAssumedReadOnly(A, CallIRP, *this, IsKnown); |
0 |
4172 |
return AA::isAssumedReadOnly(A, CallIRP, *this, IsKnown); |
0 |
| 4173 |
} |
--- |
4173 |
} |
--- |
| 4174 |
}; |
--- |
4174 |
}; |
--- |
| 4175 |
|
--- |
4175 |
|
--- |
| 4176 |
struct AAIsDeadFloating : public AAIsDeadValueImpl { |
--- |
4176 |
struct AAIsDeadFloating : public AAIsDeadValueImpl { |
--- |
| 4177 |
AAIsDeadFloating(const IRPosition &IRP, Attributor &A) |
0 |
4177 |
AAIsDeadFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 4178 |
: AAIsDeadValueImpl(IRP, A) {} |
0 |
4178 |
: AAIsDeadValueImpl(IRP, A) {} |
0 |
| 4179 |
|
--- |
4179 |
|
--- |
| 4180 |
/// See AbstractAttribute::initialize(...). |
--- |
4180 |
/// See AbstractAttribute::initialize(...). |
--- |
| 4181 |
void initialize(Attributor &A) override { |
0 |
4181 |
void initialize(Attributor &A) override { |
0 |
| 4182 |
AAIsDeadValueImpl::initialize(A); |
0 |
4182 |
AAIsDeadValueImpl::initialize(A); |
0 |
| 4183 |
|
--- |
4183 |
|
--- |
| 4184 |
if (isa(getAssociatedValue())) { |
0 |
4184 |
if (isa(getAssociatedValue())) { |
0 |
| 4185 |
indicatePessimisticFixpoint(); |
0 |
4185 |
indicatePessimisticFixpoint(); |
0 |
| 4186 |
return; |
0 |
4186 |
return; |
0 |
| 4187 |
} |
--- |
4187 |
} |
--- |
| 4188 |
|
--- |
4188 |
|
--- |
| 4189 |
Instruction *I = dyn_cast(&getAssociatedValue()); |
0 |
4189 |
Instruction *I = dyn_cast(&getAssociatedValue()); |
0 |
| 4190 |
if (!isAssumedSideEffectFree(A, I)) { |
0 |
4190 |
if (!isAssumedSideEffectFree(A, I)) { |
0 |
| 4191 |
if (!isa_and_nonnull(I) && !isa_and_nonnull(I)) |
0 |
4191 |
if (!isa_and_nonnull(I) && !isa_and_nonnull(I)) |
0 |
| 4192 |
indicatePessimisticFixpoint(); |
0 |
4192 |
indicatePessimisticFixpoint(); |
0 |
| 4193 |
else |
--- |
4193 |
else |
--- |
| 4194 |
removeAssumedBits(HAS_NO_EFFECT); |
0 |
4194 |
removeAssumedBits(HAS_NO_EFFECT); |
0 |
| 4195 |
} |
--- |
4195 |
} |
--- |
| 4196 |
} |
--- |
4196 |
} |
--- |
| 4197 |
|
--- |
4197 |
|
--- |
| 4198 |
bool isDeadFence(Attributor &A, FenceInst &FI) { |
0 |
4198 |
bool isDeadFence(Attributor &A, FenceInst &FI) { |
0 |
| 4199 |
const auto *ExecDomainAA = A.lookupAAFor( |
0 |
4199 |
const auto *ExecDomainAA = A.lookupAAFor( |
0 |
| 4200 |
IRPosition::function(*FI.getFunction()), *this, DepClassTy::NONE); |
0 |
4200 |
IRPosition::function(*FI.getFunction()), *this, DepClassTy::NONE); |
0 |
| 4201 |
if (!ExecDomainAA || !ExecDomainAA->isNoOpFence(FI)) |
0 |
4201 |
if (!ExecDomainAA || !ExecDomainAA->isNoOpFence(FI)) |
0 |
| 4202 |
return false; |
0 |
4202 |
return false; |
0 |
| 4203 |
A.recordDependence(*ExecDomainAA, *this, DepClassTy::OPTIONAL); |
0 |
4203 |
A.recordDependence(*ExecDomainAA, *this, DepClassTy::OPTIONAL); |
0 |
| 4204 |
return true; |
0 |
4204 |
return true; |
0 |
| 4205 |
} |
--- |
4205 |
} |
--- |
| 4206 |
|
--- |
4206 |
|
--- |
| 4207 |
bool isDeadStore(Attributor &A, StoreInst &SI, |
0 |
4207 |
bool isDeadStore(Attributor &A, StoreInst &SI, |
0 |
| 4208 |
SmallSetVector *AssumeOnlyInst = nullptr) { |
--- |
4208 |
SmallSetVector *AssumeOnlyInst = nullptr) { |
--- |
| 4209 |
// Lang ref now states volatile store is not UB/dead, let's skip them. |
--- |
4209 |
// Lang ref now states volatile store is not UB/dead, let's skip them. |
--- |
| 4210 |
if (SI.isVolatile()) |
0 |
4210 |
if (SI.isVolatile()) |
0 |
| 4211 |
return false; |
0 |
4211 |
return false; |
0 |
| 4212 |
|
--- |
4212 |
|
--- |
| 4213 |
// If we are collecting assumes to be deleted we are in the manifest stage. |
--- |
4213 |
// If we are collecting assumes to be deleted we are in the manifest stage. |
--- |
| 4214 |
// It's problematic to collect the potential copies again now so we use the |
--- |
4214 |
// It's problematic to collect the potential copies again now so we use the |
--- |
| 4215 |
// cached ones. |
--- |
4215 |
// cached ones. |
--- |
| 4216 |
bool UsedAssumedInformation = false; |
0 |
4216 |
bool UsedAssumedInformation = false; |
0 |
| 4217 |
if (!AssumeOnlyInst) { |
0 |
4217 |
if (!AssumeOnlyInst) { |
0 |
| 4218 |
PotentialCopies.clear(); |
0 |
4218 |
PotentialCopies.clear(); |
0 |
| 4219 |
if (!AA::getPotentialCopiesOfStoredValue(A, SI, PotentialCopies, *this, |
0 |
4219 |
if (!AA::getPotentialCopiesOfStoredValue(A, SI, PotentialCopies, *this, |
0 |
| 4220 |
UsedAssumedInformation)) { |
--- |
4220 |
UsedAssumedInformation)) { |
--- |
| 4221 |
LLVM_DEBUG( |
0 |
4221 |
LLVM_DEBUG( |
0 |
| 4222 |
dbgs() |
--- |
4222 |
dbgs() |
--- |
| 4223 |
<< "[AAIsDead] Could not determine potential copies of store!\n"); |
--- |
4223 |
<< "[AAIsDead] Could not determine potential copies of store!\n"); |
--- |
| 4224 |
return false; |
0 |
4224 |
return false; |
0 |
| 4225 |
} |
--- |
4225 |
} |
--- |
| 4226 |
} |
--- |
4226 |
} |
--- |
| 4227 |
LLVM_DEBUG(dbgs() << "[AAIsDead] Store has " << PotentialCopies.size() |
0 |
4227 |
LLVM_DEBUG(dbgs() << "[AAIsDead] Store has " << PotentialCopies.size() |
0 |
| 4228 |
<< " potential copies.\n"); |
--- |
4228 |
<< " potential copies.\n"); |
--- |
| 4229 |
|
--- |
4229 |
|
--- |
| 4230 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
4230 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
| 4231 |
return llvm::all_of(PotentialCopies, [&](Value *V) { |
0 |
4231 |
return llvm::all_of(PotentialCopies, [&](Value *V) { |
0 |
| 4232 |
if (A.isAssumedDead(IRPosition::value(*V), this, nullptr, |
0 |
4232 |
if (A.isAssumedDead(IRPosition::value(*V), this, nullptr, |
0 |
| 4233 |
UsedAssumedInformation)) |
0 |
4233 |
UsedAssumedInformation)) |
0 |
| 4234 |
return true; |
0 |
4234 |
return true; |
0 |
| 4235 |
if (auto *LI = dyn_cast(V)) { |
0 |
4235 |
if (auto *LI = dyn_cast(V)) { |
0 |
| 4236 |
if (llvm::all_of(LI->uses(), [&](const Use &U) { |
0 |
4236 |
if (llvm::all_of(LI->uses(), [&](const Use &U) { |
0 |
| 4237 |
auto &UserI = cast(*U.getUser()); |
0 |
4237 |
auto &UserI = cast(*U.getUser()); |
0 |
| 4238 |
if (InfoCache.isOnlyUsedByAssume(UserI)) { |
0 |
4238 |
if (InfoCache.isOnlyUsedByAssume(UserI)) { |
0 |
| 4239 |
if (AssumeOnlyInst) |
0 |
4239 |
if (AssumeOnlyInst) |
0 |
| 4240 |
AssumeOnlyInst->insert(&UserI); |
0 |
4240 |
AssumeOnlyInst->insert(&UserI); |
0 |
| 4241 |
return true; |
0 |
4241 |
return true; |
0 |
| 4242 |
} |
--- |
4242 |
} |
--- |
| 4243 |
return A.isAssumedDead(U, this, nullptr, UsedAssumedInformation); |
0 |
4243 |
return A.isAssumedDead(U, this, nullptr, UsedAssumedInformation); |
0 |
| 4244 |
})) { |
--- |
4244 |
})) { |
--- |
| 4245 |
return true; |
0 |
4245 |
return true; |
0 |
| 4246 |
} |
--- |
4246 |
} |
--- |
| 4247 |
} |
--- |
4247 |
} |
--- |
| 4248 |
LLVM_DEBUG(dbgs() << "[AAIsDead] Potential copy " << *V |
0 |
4248 |
LLVM_DEBUG(dbgs() << "[AAIsDead] Potential copy " << *V |
0 |
| 4249 |
<< " is assumed live!\n"); |
--- |
4249 |
<< " is assumed live!\n"); |
--- |
| 4250 |
return false; |
0 |
4250 |
return false; |
0 |
| 4251 |
}); |
0 |
4251 |
}); |
0 |
| 4252 |
} |
--- |
4252 |
} |
--- |
| 4253 |
|
--- |
4253 |
|
--- |
| 4254 |
/// See AbstractAttribute::getAsStr(). |
--- |
4254 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 4255 |
const std::string getAsStr(Attributor *A) const override { |
0 |
4255 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 4256 |
Instruction *I = dyn_cast(&getAssociatedValue()); |
0 |
4256 |
Instruction *I = dyn_cast(&getAssociatedValue()); |
0 |
| 4257 |
if (isa_and_nonnull(I)) |
0 |
4257 |
if (isa_and_nonnull(I)) |
0 |
| 4258 |
if (isValidState()) |
0 |
4258 |
if (isValidState()) |
0 |
| 4259 |
return "assumed-dead-store"; |
0 |
4259 |
return "assumed-dead-store"; |
0 |
| 4260 |
if (isa_and_nonnull(I)) |
0 |
4260 |
if (isa_and_nonnull(I)) |
0 |
| 4261 |
if (isValidState()) |
0 |
4261 |
if (isValidState()) |
0 |
| 4262 |
return "assumed-dead-fence"; |
0 |
4262 |
return "assumed-dead-fence"; |
0 |
| 4263 |
return AAIsDeadValueImpl::getAsStr(A); |
0 |
4263 |
return AAIsDeadValueImpl::getAsStr(A); |
0 |
| 4264 |
} |
--- |
4264 |
} |
--- |
| 4265 |
|
--- |
4265 |
|
--- |
| 4266 |
/// See AbstractAttribute::updateImpl(...). |
--- |
4266 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 4267 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
4267 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 4268 |
Instruction *I = dyn_cast(&getAssociatedValue()); |
0 |
4268 |
Instruction *I = dyn_cast(&getAssociatedValue()); |
0 |
| 4269 |
if (auto *SI = dyn_cast_or_null(I)) { |
0 |
4269 |
if (auto *SI = dyn_cast_or_null(I)) { |
0 |
| 4270 |
if (!isDeadStore(A, *SI)) |
0 |
4270 |
if (!isDeadStore(A, *SI)) |
0 |
| 4271 |
return indicatePessimisticFixpoint(); |
0 |
4271 |
return indicatePessimisticFixpoint(); |
0 |
| 4272 |
} else if (auto *FI = dyn_cast_or_null(I)) { |
0 |
4272 |
} else if (auto *FI = dyn_cast_or_null(I)) { |
0 |
| 4273 |
if (!isDeadFence(A, *FI)) |
0 |
4273 |
if (!isDeadFence(A, *FI)) |
0 |
| 4274 |
return indicatePessimisticFixpoint(); |
0 |
4274 |
return indicatePessimisticFixpoint(); |
0 |
| 4275 |
} else { |
--- |
4275 |
} else { |
--- |
| 4276 |
if (!isAssumedSideEffectFree(A, I)) |
0 |
4276 |
if (!isAssumedSideEffectFree(A, I)) |
0 |
| 4277 |
return indicatePessimisticFixpoint(); |
0 |
4277 |
return indicatePessimisticFixpoint(); |
0 |
| 4278 |
if (!areAllUsesAssumedDead(A, getAssociatedValue())) |
0 |
4278 |
if (!areAllUsesAssumedDead(A, getAssociatedValue())) |
0 |
| 4279 |
return indicatePessimisticFixpoint(); |
0 |
4279 |
return indicatePessimisticFixpoint(); |
0 |
| 4280 |
} |
--- |
4280 |
} |
--- |
| 4281 |
return ChangeStatus::UNCHANGED; |
0 |
4281 |
return ChangeStatus::UNCHANGED; |
0 |
| 4282 |
} |
--- |
4282 |
} |
--- |
| 4283 |
|
--- |
4283 |
|
--- |
| 4284 |
bool isRemovableStore() const override { |
0 |
4284 |
bool isRemovableStore() const override { |
0 |
| 4285 |
return isAssumed(IS_REMOVABLE) && isa(&getAssociatedValue()); |
0 |
4285 |
return isAssumed(IS_REMOVABLE) && isa(&getAssociatedValue()); |
0 |
| 4286 |
} |
--- |
4286 |
} |
--- |
| 4287 |
|
--- |
4287 |
|
--- |
| 4288 |
/// See AbstractAttribute::manifest(...). |
--- |
4288 |
/// See AbstractAttribute::manifest(...). |
--- |
| 4289 |
ChangeStatus manifest(Attributor &A) override { |
0 |
4289 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 4290 |
Value &V = getAssociatedValue(); |
0 |
4290 |
Value &V = getAssociatedValue(); |
0 |
| 4291 |
if (auto *I = dyn_cast(&V)) { |
0 |
4291 |
if (auto *I = dyn_cast(&V)) { |
0 |
| 4292 |
// If we get here we basically know the users are all dead. We check if |
--- |
4292 |
// If we get here we basically know the users are all dead. We check if |
--- |
| 4293 |
// isAssumedSideEffectFree returns true here again because it might not be |
--- |
4293 |
// isAssumedSideEffectFree returns true here again because it might not be |
--- |
| 4294 |
// the case and only the users are dead but the instruction (=call) is |
--- |
4294 |
// the case and only the users are dead but the instruction (=call) is |
--- |
| 4295 |
// still needed. |
--- |
4295 |
// still needed. |
--- |
| 4296 |
if (auto *SI = dyn_cast(I)) { |
0 |
4296 |
if (auto *SI = dyn_cast(I)) { |
0 |
| 4297 |
SmallSetVector AssumeOnlyInst; |
0 |
4297 |
SmallSetVector AssumeOnlyInst; |
0 |
| 4298 |
bool IsDead = isDeadStore(A, *SI, &AssumeOnlyInst); |
0 |
4298 |
bool IsDead = isDeadStore(A, *SI, &AssumeOnlyInst); |
0 |
| 4299 |
(void)IsDead; |
--- |
4299 |
(void)IsDead; |
--- |
| 4300 |
assert(IsDead && "Store was assumed to be dead!"); |
0 |
4300 |
assert(IsDead && "Store was assumed to be dead!"); |
0 |
| 4301 |
A.deleteAfterManifest(*I); |
0 |
4301 |
A.deleteAfterManifest(*I); |
0 |
| 4302 |
for (size_t i = 0; i < AssumeOnlyInst.size(); ++i) { |
0 |
4302 |
for (size_t i = 0; i < AssumeOnlyInst.size(); ++i) { |
0 |
| 4303 |
Instruction *AOI = AssumeOnlyInst[i]; |
0 |
4303 |
Instruction *AOI = AssumeOnlyInst[i]; |
0 |
| 4304 |
for (auto *Usr : AOI->users()) |
0 |
4304 |
for (auto *Usr : AOI->users()) |
0 |
| 4305 |
AssumeOnlyInst.insert(cast(Usr)); |
0 |
4305 |
AssumeOnlyInst.insert(cast(Usr)); |
0 |
| 4306 |
A.deleteAfterManifest(*AOI); |
0 |
4306 |
A.deleteAfterManifest(*AOI); |
0 |
| 4307 |
} |
--- |
4307 |
} |
--- |
| 4308 |
return ChangeStatus::CHANGED; |
0 |
4308 |
return ChangeStatus::CHANGED; |
0 |
| 4309 |
} |
0 |
4309 |
} |
0 |
| 4310 |
if (auto *FI = dyn_cast(I)) { |
0 |
4310 |
if (auto *FI = dyn_cast(I)) { |
0 |
| 4311 |
assert(isDeadFence(A, *FI)); |
0 |
4311 |
assert(isDeadFence(A, *FI)); |
0 |
| 4312 |
A.deleteAfterManifest(*FI); |
0 |
4312 |
A.deleteAfterManifest(*FI); |
0 |
| 4313 |
return ChangeStatus::CHANGED; |
0 |
4313 |
return ChangeStatus::CHANGED; |
0 |
| 4314 |
} |
--- |
4314 |
} |
--- |
| 4315 |
if (isAssumedSideEffectFree(A, I) && !isa(I)) { |
0 |
4315 |
if (isAssumedSideEffectFree(A, I) && !isa(I)) { |
0 |
| 4316 |
A.deleteAfterManifest(*I); |
0 |
4316 |
A.deleteAfterManifest(*I); |
0 |
| 4317 |
return ChangeStatus::CHANGED; |
0 |
4317 |
return ChangeStatus::CHANGED; |
0 |
| 4318 |
} |
--- |
4318 |
} |
--- |
| 4319 |
} |
--- |
4319 |
} |
--- |
| 4320 |
return ChangeStatus::UNCHANGED; |
0 |
4320 |
return ChangeStatus::UNCHANGED; |
0 |
| 4321 |
} |
--- |
4321 |
} |
--- |
| 4322 |
|
--- |
4322 |
|
--- |
| 4323 |
/// See AbstractAttribute::trackStatistics() |
--- |
4323 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 4324 |
void trackStatistics() const override { |
0 |
4324 |
void trackStatistics() const override { |
0 |
| 4325 |
STATS_DECLTRACK_FLOATING_ATTR(IsDead) |
0 |
4325 |
STATS_DECLTRACK_FLOATING_ATTR(IsDead) |
0 |
| 4326 |
} |
0 |
4326 |
} |
0 |
| 4327 |
|
--- |
4327 |
|
--- |
| 4328 |
private: |
--- |
4328 |
private: |
--- |
| 4329 |
// The potential copies of a dead store, used for deletion during manifest. |
--- |
4329 |
// The potential copies of a dead store, used for deletion during manifest. |
--- |
| 4330 |
SmallSetVector PotentialCopies; |
--- |
4330 |
SmallSetVector PotentialCopies; |
--- |
| 4331 |
}; |
--- |
4331 |
}; |
--- |
| 4332 |
|
--- |
4332 |
|
--- |
| 4333 |
struct AAIsDeadArgument : public AAIsDeadFloating { |
--- |
4333 |
struct AAIsDeadArgument : public AAIsDeadFloating { |
--- |
| 4334 |
AAIsDeadArgument(const IRPosition &IRP, Attributor &A) |
0 |
4334 |
AAIsDeadArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 4335 |
: AAIsDeadFloating(IRP, A) {} |
0 |
4335 |
: AAIsDeadFloating(IRP, A) {} |
0 |
| 4336 |
|
--- |
4336 |
|
--- |
| 4337 |
/// See AbstractAttribute::manifest(...). |
--- |
4337 |
/// See AbstractAttribute::manifest(...). |
--- |
| 4338 |
ChangeStatus manifest(Attributor &A) override { |
0 |
4338 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 4339 |
Argument &Arg = *getAssociatedArgument(); |
0 |
4339 |
Argument &Arg = *getAssociatedArgument(); |
0 |
| 4340 |
if (A.isValidFunctionSignatureRewrite(Arg, /* ReplacementTypes */ {})) |
0 |
4340 |
if (A.isValidFunctionSignatureRewrite(Arg, /* ReplacementTypes */ {})) |
0 |
| 4341 |
if (A.registerFunctionSignatureRewrite( |
0 |
4341 |
if (A.registerFunctionSignatureRewrite( |
0 |
| 4342 |
Arg, /* ReplacementTypes */ {}, |
--- |
4342 |
Arg, /* ReplacementTypes */ {}, |
--- |
| 4343 |
Attributor::ArgumentReplacementInfo::CalleeRepairCBTy{}, |
0 |
4343 |
Attributor::ArgumentReplacementInfo::CalleeRepairCBTy{}, |
0 |
| 4344 |
Attributor::ArgumentReplacementInfo::ACSRepairCBTy{})) { |
0 |
4344 |
Attributor::ArgumentReplacementInfo::ACSRepairCBTy{})) { |
0 |
| 4345 |
return ChangeStatus::CHANGED; |
0 |
4345 |
return ChangeStatus::CHANGED; |
0 |
| 4346 |
} |
--- |
4346 |
} |
--- |
| 4347 |
return ChangeStatus::UNCHANGED; |
0 |
4347 |
return ChangeStatus::UNCHANGED; |
0 |
| 4348 |
} |
--- |
4348 |
} |
--- |
| 4349 |
|
--- |
4349 |
|
--- |
| 4350 |
/// See AbstractAttribute::trackStatistics() |
--- |
4350 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 4351 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(IsDead) } |
0 |
4351 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(IsDead) } |
0 |
| 4352 |
}; |
--- |
4352 |
}; |
--- |
| 4353 |
|
--- |
4353 |
|
--- |
| 4354 |
struct AAIsDeadCallSiteArgument : public AAIsDeadValueImpl { |
--- |
4354 |
struct AAIsDeadCallSiteArgument : public AAIsDeadValueImpl { |
--- |
| 4355 |
AAIsDeadCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
4355 |
AAIsDeadCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 4356 |
: AAIsDeadValueImpl(IRP, A) {} |
0 |
4356 |
: AAIsDeadValueImpl(IRP, A) {} |
0 |
| 4357 |
|
--- |
4357 |
|
--- |
| 4358 |
/// See AbstractAttribute::initialize(...). |
--- |
4358 |
/// See AbstractAttribute::initialize(...). |
--- |
| 4359 |
void initialize(Attributor &A) override { |
0 |
4359 |
void initialize(Attributor &A) override { |
0 |
| 4360 |
AAIsDeadValueImpl::initialize(A); |
0 |
4360 |
AAIsDeadValueImpl::initialize(A); |
0 |
| 4361 |
if (isa(getAssociatedValue())) |
0 |
4361 |
if (isa(getAssociatedValue())) |
0 |
| 4362 |
indicatePessimisticFixpoint(); |
0 |
4362 |
indicatePessimisticFixpoint(); |
0 |
| 4363 |
} |
0 |
4363 |
} |
0 |
| 4364 |
|
--- |
4364 |
|
--- |
| 4365 |
/// See AbstractAttribute::updateImpl(...). |
--- |
4365 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 4366 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
4366 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 4367 |
// TODO: Once we have call site specific value information we can provide |
--- |
4367 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 4368 |
// call site specific liveness information and then it makes |
--- |
4368 |
// call site specific liveness information and then it makes |
--- |
| 4369 |
// sense to specialize attributes for call sites arguments instead of |
--- |
4369 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 4370 |
// redirecting requests to the callee argument. |
--- |
4370 |
// redirecting requests to the callee argument. |
--- |
| 4371 |
Argument *Arg = getAssociatedArgument(); |
0 |
4371 |
Argument *Arg = getAssociatedArgument(); |
0 |
| 4372 |
if (!Arg) |
0 |
4372 |
if (!Arg) |
0 |
| 4373 |
return indicatePessimisticFixpoint(); |
0 |
4373 |
return indicatePessimisticFixpoint(); |
0 |
| 4374 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
4374 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
| 4375 |
auto *ArgAA = A.getAAFor(*this, ArgPos, DepClassTy::REQUIRED); |
0 |
4375 |
auto *ArgAA = A.getAAFor(*this, ArgPos, DepClassTy::REQUIRED); |
0 |
| 4376 |
if (!ArgAA) |
0 |
4376 |
if (!ArgAA) |
0 |
| 4377 |
return indicatePessimisticFixpoint(); |
0 |
4377 |
return indicatePessimisticFixpoint(); |
0 |
| 4378 |
return clampStateAndIndicateChange(getState(), ArgAA->getState()); |
0 |
4378 |
return clampStateAndIndicateChange(getState(), ArgAA->getState()); |
0 |
| 4379 |
} |
--- |
4379 |
} |
--- |
| 4380 |
|
--- |
4380 |
|
--- |
| 4381 |
/// See AbstractAttribute::manifest(...). |
--- |
4381 |
/// See AbstractAttribute::manifest(...). |
--- |
| 4382 |
ChangeStatus manifest(Attributor &A) override { |
0 |
4382 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 4383 |
CallBase &CB = cast(getAnchorValue()); |
0 |
4383 |
CallBase &CB = cast(getAnchorValue()); |
0 |
| 4384 |
Use &U = CB.getArgOperandUse(getCallSiteArgNo()); |
0 |
4384 |
Use &U = CB.getArgOperandUse(getCallSiteArgNo()); |
0 |
| 4385 |
assert(!isa(U.get()) && |
0 |
4385 |
assert(!isa(U.get()) && |
0 |
| 4386 |
"Expected undef values to be filtered out!"); |
--- |
4386 |
"Expected undef values to be filtered out!"); |
--- |
| 4387 |
UndefValue &UV = *UndefValue::get(U->getType()); |
0 |
4387 |
UndefValue &UV = *UndefValue::get(U->getType()); |
0 |
| 4388 |
if (A.changeUseAfterManifest(U, UV)) |
0 |
4388 |
if (A.changeUseAfterManifest(U, UV)) |
0 |
| 4389 |
return ChangeStatus::CHANGED; |
0 |
4389 |
return ChangeStatus::CHANGED; |
0 |
| 4390 |
return ChangeStatus::UNCHANGED; |
0 |
4390 |
return ChangeStatus::UNCHANGED; |
0 |
| 4391 |
} |
--- |
4391 |
} |
--- |
| 4392 |
|
--- |
4392 |
|
--- |
| 4393 |
/// See AbstractAttribute::trackStatistics() |
--- |
4393 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 4394 |
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(IsDead) } |
0 |
4394 |
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(IsDead) } |
0 |
| 4395 |
}; |
--- |
4395 |
}; |
--- |
| 4396 |
|
--- |
4396 |
|
--- |
| 4397 |
struct AAIsDeadCallSiteReturned : public AAIsDeadFloating { |
--- |
4397 |
struct AAIsDeadCallSiteReturned : public AAIsDeadFloating { |
--- |
| 4398 |
AAIsDeadCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
4398 |
AAIsDeadCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 4399 |
: AAIsDeadFloating(IRP, A) {} |
0 |
4399 |
: AAIsDeadFloating(IRP, A) {} |
0 |
| 4400 |
|
--- |
4400 |
|
--- |
| 4401 |
/// See AAIsDead::isAssumedDead(). |
--- |
4401 |
/// See AAIsDead::isAssumedDead(). |
--- |
| 4402 |
bool isAssumedDead() const override { |
0 |
4402 |
bool isAssumedDead() const override { |
0 |
| 4403 |
return AAIsDeadFloating::isAssumedDead() && IsAssumedSideEffectFree; |
0 |
4403 |
return AAIsDeadFloating::isAssumedDead() && IsAssumedSideEffectFree; |
0 |
| 4404 |
} |
--- |
4404 |
} |
--- |
| 4405 |
|
--- |
4405 |
|
--- |
| 4406 |
/// See AbstractAttribute::initialize(...). |
--- |
4406 |
/// See AbstractAttribute::initialize(...). |
--- |
| 4407 |
void initialize(Attributor &A) override { |
0 |
4407 |
void initialize(Attributor &A) override { |
0 |
| 4408 |
AAIsDeadFloating::initialize(A); |
0 |
4408 |
AAIsDeadFloating::initialize(A); |
0 |
| 4409 |
if (isa(getAssociatedValue())) { |
0 |
4409 |
if (isa(getAssociatedValue())) { |
0 |
| 4410 |
indicatePessimisticFixpoint(); |
0 |
4410 |
indicatePessimisticFixpoint(); |
0 |
| 4411 |
return; |
0 |
4411 |
return; |
0 |
| 4412 |
} |
--- |
4412 |
} |
--- |
| 4413 |
|
--- |
4413 |
|
--- |
| 4414 |
// We track this separately as a secondary state. |
--- |
4414 |
// We track this separately as a secondary state. |
--- |
| 4415 |
IsAssumedSideEffectFree = isAssumedSideEffectFree(A, getCtxI()); |
0 |
4415 |
IsAssumedSideEffectFree = isAssumedSideEffectFree(A, getCtxI()); |
0 |
| 4416 |
} |
--- |
4416 |
} |
--- |
| 4417 |
|
--- |
4417 |
|
--- |
| 4418 |
/// See AbstractAttribute::updateImpl(...). |
--- |
4418 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 4419 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
4419 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 4420 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
4420 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 4421 |
if (IsAssumedSideEffectFree && !isAssumedSideEffectFree(A, getCtxI())) { |
0 |
4421 |
if (IsAssumedSideEffectFree && !isAssumedSideEffectFree(A, getCtxI())) { |
0 |
| 4422 |
IsAssumedSideEffectFree = false; |
0 |
4422 |
IsAssumedSideEffectFree = false; |
0 |
| 4423 |
Changed = ChangeStatus::CHANGED; |
0 |
4423 |
Changed = ChangeStatus::CHANGED; |
0 |
| 4424 |
} |
--- |
4424 |
} |
--- |
| 4425 |
if (!areAllUsesAssumedDead(A, getAssociatedValue())) |
0 |
4425 |
if (!areAllUsesAssumedDead(A, getAssociatedValue())) |
0 |
| 4426 |
return indicatePessimisticFixpoint(); |
0 |
4426 |
return indicatePessimisticFixpoint(); |
0 |
| 4427 |
return Changed; |
0 |
4427 |
return Changed; |
0 |
| 4428 |
} |
--- |
4428 |
} |
--- |
| 4429 |
|
--- |
4429 |
|
--- |
| 4430 |
/// See AbstractAttribute::trackStatistics() |
--- |
4430 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 4431 |
void trackStatistics() const override { |
0 |
4431 |
void trackStatistics() const override { |
0 |
| 4432 |
if (IsAssumedSideEffectFree) |
0 |
4432 |
if (IsAssumedSideEffectFree) |
0 |
| 4433 |
STATS_DECLTRACK_CSRET_ATTR(IsDead) |
0 |
4433 |
STATS_DECLTRACK_CSRET_ATTR(IsDead) |
0 |
| 4434 |
else |
--- |
4434 |
else |
--- |
| 4435 |
STATS_DECLTRACK_CSRET_ATTR(UnusedResult) |
0 |
4435 |
STATS_DECLTRACK_CSRET_ATTR(UnusedResult) |
0 |
| 4436 |
} |
0 |
4436 |
} |
0 |
| 4437 |
|
--- |
4437 |
|
--- |
| 4438 |
/// See AbstractAttribute::getAsStr(). |
--- |
4438 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 4439 |
const std::string getAsStr(Attributor *A) const override { |
0 |
4439 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 4440 |
return isAssumedDead() |
0 |
4440 |
return isAssumedDead() |
0 |
| 4441 |
? "assumed-dead" |
--- |
4441 |
? "assumed-dead" |
--- |
| 4442 |
: (getAssumed() ? "assumed-dead-users" : "assumed-live"); |
0 |
4442 |
: (getAssumed() ? "assumed-dead-users" : "assumed-live"); |
0 |
| 4443 |
} |
--- |
4443 |
} |
--- |
| 4444 |
|
--- |
4444 |
|
--- |
| 4445 |
private: |
--- |
4445 |
private: |
--- |
| 4446 |
bool IsAssumedSideEffectFree = true; |
--- |
4446 |
bool IsAssumedSideEffectFree = true; |
--- |
| 4447 |
}; |
--- |
4447 |
}; |
--- |
| 4448 |
|
--- |
4448 |
|
--- |
| 4449 |
struct AAIsDeadReturned : public AAIsDeadValueImpl { |
--- |
4449 |
struct AAIsDeadReturned : public AAIsDeadValueImpl { |
--- |
| 4450 |
AAIsDeadReturned(const IRPosition &IRP, Attributor &A) |
0 |
4450 |
AAIsDeadReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 4451 |
: AAIsDeadValueImpl(IRP, A) {} |
0 |
4451 |
: AAIsDeadValueImpl(IRP, A) {} |
0 |
| 4452 |
|
--- |
4452 |
|
--- |
| 4453 |
/// See AbstractAttribute::updateImpl(...). |
--- |
4453 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 4454 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
4454 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 4455 |
|
--- |
4455 |
|
--- |
| 4456 |
bool UsedAssumedInformation = false; |
0 |
4456 |
bool UsedAssumedInformation = false; |
0 |
| 4457 |
A.checkForAllInstructions([](Instruction &) { return true; }, *this, |
0 |
4457 |
A.checkForAllInstructions([](Instruction &) { return true; }, *this, |
0 |
| 4458 |
{Instruction::Ret}, UsedAssumedInformation); |
--- |
4458 |
{Instruction::Ret}, UsedAssumedInformation); |
--- |
| 4459 |
|
--- |
4459 |
|
--- |
| 4460 |
auto PredForCallSite = [&](AbstractCallSite ACS) { |
0 |
4460 |
auto PredForCallSite = [&](AbstractCallSite ACS) { |
0 |
| 4461 |
if (ACS.isCallbackCall() || !ACS.getInstruction()) |
0 |
4461 |
if (ACS.isCallbackCall() || !ACS.getInstruction()) |
0 |
| 4462 |
return false; |
0 |
4462 |
return false; |
0 |
| 4463 |
return areAllUsesAssumedDead(A, *ACS.getInstruction()); |
0 |
4463 |
return areAllUsesAssumedDead(A, *ACS.getInstruction()); |
0 |
| 4464 |
}; |
0 |
4464 |
}; |
0 |
| 4465 |
|
--- |
4465 |
|
--- |
| 4466 |
if (!A.checkForAllCallSites(PredForCallSite, *this, true, |
0 |
4466 |
if (!A.checkForAllCallSites(PredForCallSite, *this, true, |
0 |
| 4467 |
UsedAssumedInformation)) |
--- |
4467 |
UsedAssumedInformation)) |
--- |
| 4468 |
return indicatePessimisticFixpoint(); |
0 |
4468 |
return indicatePessimisticFixpoint(); |
0 |
| 4469 |
|
--- |
4469 |
|
--- |
| 4470 |
return ChangeStatus::UNCHANGED; |
0 |
4470 |
return ChangeStatus::UNCHANGED; |
0 |
| 4471 |
} |
--- |
4471 |
} |
--- |
| 4472 |
|
--- |
4472 |
|
--- |
| 4473 |
/// See AbstractAttribute::manifest(...). |
--- |
4473 |
/// See AbstractAttribute::manifest(...). |
--- |
| 4474 |
ChangeStatus manifest(Attributor &A) override { |
0 |
4474 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 4475 |
// TODO: Rewrite the signature to return void? |
--- |
4475 |
// TODO: Rewrite the signature to return void? |
--- |
| 4476 |
bool AnyChange = false; |
0 |
4476 |
bool AnyChange = false; |
0 |
| 4477 |
UndefValue &UV = *UndefValue::get(getAssociatedFunction()->getReturnType()); |
0 |
4477 |
UndefValue &UV = *UndefValue::get(getAssociatedFunction()->getReturnType()); |
0 |
| 4478 |
auto RetInstPred = [&](Instruction &I) { |
0 |
4478 |
auto RetInstPred = [&](Instruction &I) { |
0 |
| 4479 |
ReturnInst &RI = cast(I); |
0 |
4479 |
ReturnInst &RI = cast(I); |
0 |
| 4480 |
if (!isa(RI.getReturnValue())) |
0 |
4480 |
if (!isa(RI.getReturnValue())) |
0 |
| 4481 |
AnyChange |= A.changeUseAfterManifest(RI.getOperandUse(0), UV); |
0 |
4481 |
AnyChange |= A.changeUseAfterManifest(RI.getOperandUse(0), UV); |
0 |
| 4482 |
return true; |
0 |
4482 |
return true; |
0 |
| 4483 |
}; |
0 |
4483 |
}; |
0 |
| 4484 |
bool UsedAssumedInformation = false; |
0 |
4484 |
bool UsedAssumedInformation = false; |
0 |
| 4485 |
A.checkForAllInstructions(RetInstPred, *this, {Instruction::Ret}, |
0 |
4485 |
A.checkForAllInstructions(RetInstPred, *this, {Instruction::Ret}, |
0 |
| 4486 |
UsedAssumedInformation); |
--- |
4486 |
UsedAssumedInformation); |
--- |
| 4487 |
return AnyChange ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
4487 |
return AnyChange ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
| 4488 |
} |
--- |
4488 |
} |
--- |
| 4489 |
|
--- |
4489 |
|
--- |
| 4490 |
/// See AbstractAttribute::trackStatistics() |
--- |
4490 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 4491 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(IsDead) } |
0 |
4491 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(IsDead) } |
0 |
| 4492 |
}; |
--- |
4492 |
}; |
--- |
| 4493 |
|
--- |
4493 |
|
--- |
| 4494 |
struct AAIsDeadFunction : public AAIsDead { |
--- |
4494 |
struct AAIsDeadFunction : public AAIsDead { |
--- |
| 4495 |
AAIsDeadFunction(const IRPosition &IRP, Attributor &A) : AAIsDead(IRP, A) {} |
0 |
4495 |
AAIsDeadFunction(const IRPosition &IRP, Attributor &A) : AAIsDead(IRP, A) {} |
0 |
| 4496 |
|
--- |
4496 |
|
--- |
| 4497 |
/// See AbstractAttribute::initialize(...). |
--- |
4497 |
/// See AbstractAttribute::initialize(...). |
--- |
| 4498 |
void initialize(Attributor &A) override { |
0 |
4498 |
void initialize(Attributor &A) override { |
0 |
| 4499 |
Function *F = getAnchorScope(); |
0 |
4499 |
Function *F = getAnchorScope(); |
0 |
| 4500 |
assert(F && "Did expect an anchor function"); |
0 |
4500 |
assert(F && "Did expect an anchor function"); |
0 |
| 4501 |
if (!isAssumedDeadInternalFunction(A)) { |
0 |
4501 |
if (!isAssumedDeadInternalFunction(A)) { |
0 |
| 4502 |
ToBeExploredFrom.insert(&F->getEntryBlock().front()); |
0 |
4502 |
ToBeExploredFrom.insert(&F->getEntryBlock().front()); |
0 |
| 4503 |
assumeLive(A, F->getEntryBlock()); |
0 |
4503 |
assumeLive(A, F->getEntryBlock()); |
0 |
| 4504 |
} |
--- |
4504 |
} |
--- |
| 4505 |
} |
0 |
4505 |
} |
0 |
| 4506 |
|
--- |
4506 |
|
--- |
| 4507 |
bool isAssumedDeadInternalFunction(Attributor &A) { |
0 |
4507 |
bool isAssumedDeadInternalFunction(Attributor &A) { |
0 |
| 4508 |
if (!getAnchorScope()->hasLocalLinkage()) |
0 |
4508 |
if (!getAnchorScope()->hasLocalLinkage()) |
0 |
| 4509 |
return false; |
0 |
4509 |
return false; |
0 |
| 4510 |
bool UsedAssumedInformation = false; |
0 |
4510 |
bool UsedAssumedInformation = false; |
0 |
| 4511 |
return A.checkForAllCallSites([](AbstractCallSite) { return false; }, *this, |
0 |
4511 |
return A.checkForAllCallSites([](AbstractCallSite) { return false; }, *this, |
0 |
| 4512 |
true, UsedAssumedInformation); |
0 |
4512 |
true, UsedAssumedInformation); |
0 |
| 4513 |
} |
--- |
4513 |
} |
--- |
| 4514 |
|
--- |
4514 |
|
--- |
| 4515 |
/// See AbstractAttribute::getAsStr(). |
--- |
4515 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 4516 |
const std::string getAsStr(Attributor *A) const override { |
0 |
4516 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 4517 |
return "Live[#BB " + std::to_string(AssumedLiveBlocks.size()) + "/" + |
0 |
4517 |
return "Live[#BB " + std::to_string(AssumedLiveBlocks.size()) + "/" + |
0 |
| 4518 |
std::to_string(getAnchorScope()->size()) + "][#TBEP " + |
0 |
4518 |
std::to_string(getAnchorScope()->size()) + "][#TBEP " + |
0 |
| 4519 |
std::to_string(ToBeExploredFrom.size()) + "][#KDE " + |
0 |
4519 |
std::to_string(ToBeExploredFrom.size()) + "][#KDE " + |
0 |
| 4520 |
std::to_string(KnownDeadEnds.size()) + "]"; |
0 |
4520 |
std::to_string(KnownDeadEnds.size()) + "]"; |
0 |
| 4521 |
} |
--- |
4521 |
} |
--- |
| 4522 |
|
--- |
4522 |
|
--- |
| 4523 |
/// See AbstractAttribute::manifest(...). |
--- |
4523 |
/// See AbstractAttribute::manifest(...). |
--- |
| 4524 |
ChangeStatus manifest(Attributor &A) override { |
0 |
4524 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 4525 |
assert(getState().isValidState() && |
0 |
4525 |
assert(getState().isValidState() && |
0 |
| 4526 |
"Attempted to manifest an invalid state!"); |
--- |
4526 |
"Attempted to manifest an invalid state!"); |
--- |
| 4527 |
|
--- |
4527 |
|
--- |
| 4528 |
ChangeStatus HasChanged = ChangeStatus::UNCHANGED; |
0 |
4528 |
ChangeStatus HasChanged = ChangeStatus::UNCHANGED; |
0 |
| 4529 |
Function &F = *getAnchorScope(); |
0 |
4529 |
Function &F = *getAnchorScope(); |
0 |
| 4530 |
|
--- |
4530 |
|
--- |
| 4531 |
if (AssumedLiveBlocks.empty()) { |
0 |
4531 |
if (AssumedLiveBlocks.empty()) { |
0 |
| 4532 |
A.deleteAfterManifest(F); |
0 |
4532 |
A.deleteAfterManifest(F); |
0 |
| 4533 |
return ChangeStatus::CHANGED; |
0 |
4533 |
return ChangeStatus::CHANGED; |
0 |
| 4534 |
} |
--- |
4534 |
} |
--- |
| 4535 |
|
--- |
4535 |
|
--- |
| 4536 |
// Flag to determine if we can change an invoke to a call assuming the |
--- |
4536 |
// Flag to determine if we can change an invoke to a call assuming the |
--- |
| 4537 |
// callee is nounwind. This is not possible if the personality of the |
--- |
4537 |
// callee is nounwind. This is not possible if the personality of the |
--- |
| 4538 |
// function allows to catch asynchronous exceptions. |
--- |
4538 |
// function allows to catch asynchronous exceptions. |
--- |
| 4539 |
bool Invoke2CallAllowed = !mayCatchAsynchronousExceptions(F); |
0 |
4539 |
bool Invoke2CallAllowed = !mayCatchAsynchronousExceptions(F); |
0 |
| 4540 |
|
--- |
4540 |
|
--- |
| 4541 |
KnownDeadEnds.set_union(ToBeExploredFrom); |
0 |
4541 |
KnownDeadEnds.set_union(ToBeExploredFrom); |
0 |
| 4542 |
for (const Instruction *DeadEndI : KnownDeadEnds) { |
0 |
4542 |
for (const Instruction *DeadEndI : KnownDeadEnds) { |
0 |
| 4543 |
auto *CB = dyn_cast(DeadEndI); |
0 |
4543 |
auto *CB = dyn_cast(DeadEndI); |
0 |
| 4544 |
if (!CB) |
0 |
4544 |
if (!CB) |
0 |
| 4545 |
continue; |
0 |
4545 |
continue; |
0 |
| 4546 |
bool IsKnownNoReturn; |
--- |
4546 |
bool IsKnownNoReturn; |
--- |
| 4547 |
bool MayReturn = !AA::hasAssumedIRAttr( |
0 |
4547 |
bool MayReturn = !AA::hasAssumedIRAttr( |
0 |
| 4548 |
A, this, IRPosition::callsite_function(*CB), DepClassTy::OPTIONAL, |
0 |
4548 |
A, this, IRPosition::callsite_function(*CB), DepClassTy::OPTIONAL, |
0 |
| 4549 |
IsKnownNoReturn); |
0 |
4549 |
IsKnownNoReturn); |
0 |
| 4550 |
if (MayReturn && (!Invoke2CallAllowed || !isa(CB))) |
0 |
4550 |
if (MayReturn && (!Invoke2CallAllowed || !isa(CB))) |
0 |
| 4551 |
continue; |
0 |
4551 |
continue; |
0 |
| 4552 |
|
--- |
4552 |
|
--- |
| 4553 |
if (auto *II = dyn_cast(DeadEndI)) |
0 |
4553 |
if (auto *II = dyn_cast(DeadEndI)) |
0 |
| 4554 |
A.registerInvokeWithDeadSuccessor(const_cast(*II)); |
0 |
4554 |
A.registerInvokeWithDeadSuccessor(const_cast(*II)); |
0 |
| 4555 |
else |
--- |
4555 |
else |
--- |
| 4556 |
A.changeToUnreachableAfterManifest( |
0 |
4556 |
A.changeToUnreachableAfterManifest( |
0 |
| 4557 |
const_cast(DeadEndI->getNextNode())); |
0 |
4557 |
const_cast(DeadEndI->getNextNode())); |
0 |
| 4558 |
HasChanged = ChangeStatus::CHANGED; |
0 |
4558 |
HasChanged = ChangeStatus::CHANGED; |
0 |
| 4559 |
} |
--- |
4559 |
} |
--- |
| 4560 |
|
--- |
4560 |
|
--- |
| 4561 |
STATS_DECL(AAIsDead, BasicBlock, "Number of dead basic blocks deleted."); |
--- |
4561 |
STATS_DECL(AAIsDead, BasicBlock, "Number of dead basic blocks deleted."); |
--- |
| 4562 |
for (BasicBlock &BB : F) |
0 |
4562 |
for (BasicBlock &BB : F) |
0 |
| 4563 |
if (!AssumedLiveBlocks.count(&BB)) { |
0 |
4563 |
if (!AssumedLiveBlocks.count(&BB)) { |
0 |
| 4564 |
A.deleteAfterManifest(BB); |
0 |
4564 |
A.deleteAfterManifest(BB); |
0 |
| 4565 |
++BUILD_STAT_NAME(AAIsDead, BasicBlock); |
0 |
4565 |
++BUILD_STAT_NAME(AAIsDead, BasicBlock); |
0 |
| 4566 |
HasChanged = ChangeStatus::CHANGED; |
0 |
4566 |
HasChanged = ChangeStatus::CHANGED; |
0 |
| 4567 |
} |
--- |
4567 |
} |
--- |
| 4568 |
|
--- |
4568 |
|
--- |
| 4569 |
return HasChanged; |
0 |
4569 |
return HasChanged; |
0 |
| 4570 |
} |
--- |
4570 |
} |
--- |
| 4571 |
|
--- |
4571 |
|
--- |
| 4572 |
/// See AbstractAttribute::updateImpl(...). |
--- |
4572 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 4573 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
4573 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
| 4574 |
|
--- |
4574 |
|
--- |
| 4575 |
bool isEdgeDead(const BasicBlock *From, const BasicBlock *To) const override { |
0 |
4575 |
bool isEdgeDead(const BasicBlock *From, const BasicBlock *To) const override { |
0 |
| 4576 |
assert(From->getParent() == getAnchorScope() && |
0 |
4576 |
assert(From->getParent() == getAnchorScope() && |
0 |
| 4577 |
To->getParent() == getAnchorScope() && |
--- |
4577 |
To->getParent() == getAnchorScope() && |
--- |
| 4578 |
"Used AAIsDead of the wrong function"); |
--- |
4578 |
"Used AAIsDead of the wrong function"); |
--- |
| 4579 |
return isValidState() && !AssumedLiveEdges.count(std::make_pair(From, To)); |
0 |
4579 |
return isValidState() && !AssumedLiveEdges.count(std::make_pair(From, To)); |
0 |
| 4580 |
} |
--- |
4580 |
} |
--- |
| 4581 |
|
--- |
4581 |
|
--- |
| 4582 |
/// See AbstractAttribute::trackStatistics() |
--- |
4582 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 4583 |
void trackStatistics() const override {} |
0 |
4583 |
void trackStatistics() const override {} |
0 |
| 4584 |
|
--- |
4584 |
|
--- |
| 4585 |
/// Returns true if the function is assumed dead. |
--- |
4585 |
/// Returns true if the function is assumed dead. |
--- |
| 4586 |
bool isAssumedDead() const override { return false; } |
0 |
4586 |
bool isAssumedDead() const override { return false; } |
0 |
| 4587 |
|
--- |
4587 |
|
--- |
| 4588 |
/// See AAIsDead::isKnownDead(). |
--- |
4588 |
/// See AAIsDead::isKnownDead(). |
--- |
| 4589 |
bool isKnownDead() const override { return false; } |
0 |
4589 |
bool isKnownDead() const override { return false; } |
0 |
| 4590 |
|
--- |
4590 |
|
--- |
| 4591 |
/// See AAIsDead::isAssumedDead(BasicBlock *). |
--- |
4591 |
/// See AAIsDead::isAssumedDead(BasicBlock *). |
--- |
| 4592 |
bool isAssumedDead(const BasicBlock *BB) const override { |
0 |
4592 |
bool isAssumedDead(const BasicBlock *BB) const override { |
0 |
| 4593 |
assert(BB->getParent() == getAnchorScope() && |
0 |
4593 |
assert(BB->getParent() == getAnchorScope() && |
0 |
| 4594 |
"BB must be in the same anchor scope function."); |
--- |
4594 |
"BB must be in the same anchor scope function."); |
--- |
| 4595 |
|
--- |
4595 |
|
--- |
| 4596 |
if (!getAssumed()) |
0 |
4596 |
if (!getAssumed()) |
0 |
| 4597 |
return false; |
0 |
4597 |
return false; |
0 |
| 4598 |
return !AssumedLiveBlocks.count(BB); |
0 |
4598 |
return !AssumedLiveBlocks.count(BB); |
0 |
| 4599 |
} |
--- |
4599 |
} |
--- |
| 4600 |
|
--- |
4600 |
|
--- |
| 4601 |
/// See AAIsDead::isKnownDead(BasicBlock *). |
--- |
4601 |
/// See AAIsDead::isKnownDead(BasicBlock *). |
--- |
| 4602 |
bool isKnownDead(const BasicBlock *BB) const override { |
0 |
4602 |
bool isKnownDead(const BasicBlock *BB) const override { |
0 |
| 4603 |
return getKnown() && isAssumedDead(BB); |
0 |
4603 |
return getKnown() && isAssumedDead(BB); |
0 |
| 4604 |
} |
--- |
4604 |
} |
--- |
| 4605 |
|
--- |
4605 |
|
--- |
| 4606 |
/// See AAIsDead::isAssumed(Instruction *I). |
--- |
4606 |
/// See AAIsDead::isAssumed(Instruction *I). |
--- |
| 4607 |
bool isAssumedDead(const Instruction *I) const override { |
0 |
4607 |
bool isAssumedDead(const Instruction *I) const override { |
0 |
| 4608 |
assert(I->getParent()->getParent() == getAnchorScope() && |
0 |
4608 |
assert(I->getParent()->getParent() == getAnchorScope() && |
0 |
| 4609 |
"Instruction must be in the same anchor scope function."); |
--- |
4609 |
"Instruction must be in the same anchor scope function."); |
--- |
| 4610 |
|
--- |
4610 |
|
--- |
| 4611 |
if (!getAssumed()) |
0 |
4611 |
if (!getAssumed()) |
0 |
| 4612 |
return false; |
0 |
4612 |
return false; |
0 |
| 4613 |
|
--- |
4613 |
|
--- |
| 4614 |
// If it is not in AssumedLiveBlocks then it for sure dead. |
--- |
4614 |
// If it is not in AssumedLiveBlocks then it for sure dead. |
--- |
| 4615 |
// Otherwise, it can still be after noreturn call in a live block. |
--- |
4615 |
// Otherwise, it can still be after noreturn call in a live block. |
--- |
| 4616 |
if (!AssumedLiveBlocks.count(I->getParent())) |
0 |
4616 |
if (!AssumedLiveBlocks.count(I->getParent())) |
0 |
| 4617 |
return true; |
0 |
4617 |
return true; |
0 |
| 4618 |
|
--- |
4618 |
|
--- |
| 4619 |
// If it is not after a liveness barrier it is live. |
--- |
4619 |
// If it is not after a liveness barrier it is live. |
--- |
| 4620 |
const Instruction *PrevI = I->getPrevNode(); |
0 |
4620 |
const Instruction *PrevI = I->getPrevNode(); |
0 |
| 4621 |
while (PrevI) { |
0 |
4621 |
while (PrevI) { |
0 |
| 4622 |
if (KnownDeadEnds.count(PrevI) || ToBeExploredFrom.count(PrevI)) |
0 |
4622 |
if (KnownDeadEnds.count(PrevI) || ToBeExploredFrom.count(PrevI)) |
0 |
| 4623 |
return true; |
0 |
4623 |
return true; |
0 |
| 4624 |
PrevI = PrevI->getPrevNode(); |
0 |
4624 |
PrevI = PrevI->getPrevNode(); |
0 |
| 4625 |
} |
--- |
4625 |
} |
--- |
| 4626 |
return false; |
0 |
4626 |
return false; |
0 |
| 4627 |
} |
--- |
4627 |
} |
--- |
| 4628 |
|
--- |
4628 |
|
--- |
| 4629 |
/// See AAIsDead::isKnownDead(Instruction *I). |
--- |
4629 |
/// See AAIsDead::isKnownDead(Instruction *I). |
--- |
| 4630 |
bool isKnownDead(const Instruction *I) const override { |
0 |
4630 |
bool isKnownDead(const Instruction *I) const override { |
0 |
| 4631 |
return getKnown() && isAssumedDead(I); |
0 |
4631 |
return getKnown() && isAssumedDead(I); |
0 |
| 4632 |
} |
--- |
4632 |
} |
--- |
| 4633 |
|
--- |
4633 |
|
--- |
| 4634 |
/// Assume \p BB is (partially) live now and indicate to the Attributor \p A |
--- |
4634 |
/// Assume \p BB is (partially) live now and indicate to the Attributor \p A |
--- |
| 4635 |
/// that internal function called from \p BB should now be looked at. |
--- |
4635 |
/// that internal function called from \p BB should now be looked at. |
--- |
| 4636 |
bool assumeLive(Attributor &A, const BasicBlock &BB) { |
0 |
4636 |
bool assumeLive(Attributor &A, const BasicBlock &BB) { |
0 |
| 4637 |
if (!AssumedLiveBlocks.insert(&BB).second) |
0 |
4637 |
if (!AssumedLiveBlocks.insert(&BB).second) |
0 |
| 4638 |
return false; |
0 |
4638 |
return false; |
0 |
| 4639 |
|
--- |
4639 |
|
--- |
| 4640 |
// We assume that all of BB is (probably) live now and if there are calls to |
--- |
4640 |
// We assume that all of BB is (probably) live now and if there are calls to |
--- |
| 4641 |
// internal functions we will assume that those are now live as well. This |
--- |
4641 |
// internal functions we will assume that those are now live as well. This |
--- |
| 4642 |
// is a performance optimization for blocks with calls to a lot of internal |
--- |
4642 |
// is a performance optimization for blocks with calls to a lot of internal |
--- |
| 4643 |
// functions. It can however cause dead functions to be treated as live. |
--- |
4643 |
// functions. It can however cause dead functions to be treated as live. |
--- |
| 4644 |
for (const Instruction &I : BB) |
0 |
4644 |
for (const Instruction &I : BB) |
0 |
| 4645 |
if (const auto *CB = dyn_cast(&I)) |
0 |
4645 |
if (const auto *CB = dyn_cast(&I)) |
0 |
| 4646 |
if (auto *F = dyn_cast_if_present(CB->getCalledOperand())) |
0 |
4646 |
if (auto *F = dyn_cast_if_present(CB->getCalledOperand())) |
0 |
| 4647 |
if (F->hasLocalLinkage()) |
0 |
4647 |
if (F->hasLocalLinkage()) |
0 |
| 4648 |
A.markLiveInternalFunction(*F); |
0 |
4648 |
A.markLiveInternalFunction(*F); |
0 |
| 4649 |
return true; |
0 |
4649 |
return true; |
0 |
| 4650 |
} |
--- |
4650 |
} |
--- |
| 4651 |
|
--- |
4651 |
|
--- |
| 4652 |
/// Collection of instructions that need to be explored again, e.g., we |
--- |
4652 |
/// Collection of instructions that need to be explored again, e.g., we |
--- |
| 4653 |
/// did assume they do not transfer control to (one of their) successors. |
--- |
4653 |
/// did assume they do not transfer control to (one of their) successors. |
--- |
| 4654 |
SmallSetVector ToBeExploredFrom; |
--- |
4654 |
SmallSetVector ToBeExploredFrom; |
--- |
| 4655 |
|
--- |
4655 |
|
--- |
| 4656 |
/// Collection of instructions that are known to not transfer control. |
--- |
4656 |
/// Collection of instructions that are known to not transfer control. |
--- |
| 4657 |
SmallSetVector KnownDeadEnds; |
--- |
4657 |
SmallSetVector KnownDeadEnds; |
--- |
| 4658 |
|
--- |
4658 |
|
--- |
| 4659 |
/// Collection of all assumed live edges |
--- |
4659 |
/// Collection of all assumed live edges |
--- |
| 4660 |
DenseSet> AssumedLiveEdges; |
--- |
4660 |
DenseSet> AssumedLiveEdges; |
--- |
| 4661 |
|
--- |
4661 |
|
--- |
| 4662 |
/// Collection of all assumed live BasicBlocks. |
--- |
4662 |
/// Collection of all assumed live BasicBlocks. |
--- |
| 4663 |
DenseSet AssumedLiveBlocks; |
--- |
4663 |
DenseSet AssumedLiveBlocks; |
--- |
| 4664 |
}; |
--- |
4664 |
}; |
--- |
| 4665 |
|
--- |
4665 |
|
--- |
| 4666 |
static bool |
--- |
4666 |
static bool |
--- |
| 4667 |
identifyAliveSuccessors(Attributor &A, const CallBase &CB, |
0 |
4667 |
identifyAliveSuccessors(Attributor &A, const CallBase &CB, |
0 |
| 4668 |
AbstractAttribute &AA, |
--- |
4668 |
AbstractAttribute &AA, |
--- |
| 4669 |
SmallVectorImpl &AliveSuccessors) { |
--- |
4669 |
SmallVectorImpl &AliveSuccessors) { |
--- |
| 4670 |
const IRPosition &IPos = IRPosition::callsite_function(CB); |
0 |
4670 |
const IRPosition &IPos = IRPosition::callsite_function(CB); |
0 |
| 4671 |
|
--- |
4671 |
|
--- |
| 4672 |
bool IsKnownNoReturn; |
--- |
4672 |
bool IsKnownNoReturn; |
--- |
| 4673 |
if (AA::hasAssumedIRAttr( |
0 |
4673 |
if (AA::hasAssumedIRAttr( |
0 |
| 4674 |
A, &AA, IPos, DepClassTy::OPTIONAL, IsKnownNoReturn)) |
--- |
4674 |
A, &AA, IPos, DepClassTy::OPTIONAL, IsKnownNoReturn)) |
--- |
| 4675 |
return !IsKnownNoReturn; |
0 |
4675 |
return !IsKnownNoReturn; |
0 |
| 4676 |
if (CB.isTerminator()) |
0 |
4676 |
if (CB.isTerminator()) |
0 |
| 4677 |
AliveSuccessors.push_back(&CB.getSuccessor(0)->front()); |
0 |
4677 |
AliveSuccessors.push_back(&CB.getSuccessor(0)->front()); |
0 |
| 4678 |
else |
--- |
4678 |
else |
--- |
| 4679 |
AliveSuccessors.push_back(CB.getNextNode()); |
0 |
4679 |
AliveSuccessors.push_back(CB.getNextNode()); |
0 |
| 4680 |
return false; |
0 |
4680 |
return false; |
0 |
| 4681 |
} |
--- |
4681 |
} |
--- |
| 4682 |
|
--- |
4682 |
|
--- |
| 4683 |
static bool |
--- |
4683 |
static bool |
--- |
| 4684 |
identifyAliveSuccessors(Attributor &A, const InvokeInst &II, |
0 |
4684 |
identifyAliveSuccessors(Attributor &A, const InvokeInst &II, |
0 |
| 4685 |
AbstractAttribute &AA, |
--- |
4685 |
AbstractAttribute &AA, |
--- |
| 4686 |
SmallVectorImpl &AliveSuccessors) { |
--- |
4686 |
SmallVectorImpl &AliveSuccessors) { |
--- |
| 4687 |
bool UsedAssumedInformation = |
--- |
4687 |
bool UsedAssumedInformation = |
--- |
| 4688 |
identifyAliveSuccessors(A, cast(II), AA, AliveSuccessors); |
0 |
4688 |
identifyAliveSuccessors(A, cast(II), AA, AliveSuccessors); |
0 |
| 4689 |
|
--- |
4689 |
|
--- |
| 4690 |
// First, determine if we can change an invoke to a call assuming the |
--- |
4690 |
// First, determine if we can change an invoke to a call assuming the |
--- |
| 4691 |
// callee is nounwind. This is not possible if the personality of the |
--- |
4691 |
// callee is nounwind. This is not possible if the personality of the |
--- |
| 4692 |
// function allows to catch asynchronous exceptions. |
--- |
4692 |
// function allows to catch asynchronous exceptions. |
--- |
| 4693 |
if (AAIsDeadFunction::mayCatchAsynchronousExceptions(*II.getFunction())) { |
0 |
4693 |
if (AAIsDeadFunction::mayCatchAsynchronousExceptions(*II.getFunction())) { |
0 |
| 4694 |
AliveSuccessors.push_back(&II.getUnwindDest()->front()); |
0 |
4694 |
AliveSuccessors.push_back(&II.getUnwindDest()->front()); |
0 |
| 4695 |
} else { |
--- |
4695 |
} else { |
--- |
| 4696 |
const IRPosition &IPos = IRPosition::callsite_function(II); |
0 |
4696 |
const IRPosition &IPos = IRPosition::callsite_function(II); |
0 |
| 4697 |
|
--- |
4697 |
|
--- |
| 4698 |
bool IsKnownNoUnwind; |
--- |
4698 |
bool IsKnownNoUnwind; |
--- |
| 4699 |
if (AA::hasAssumedIRAttr( |
0 |
4699 |
if (AA::hasAssumedIRAttr( |
0 |
| 4700 |
A, &AA, IPos, DepClassTy::OPTIONAL, IsKnownNoUnwind)) { |
--- |
4700 |
A, &AA, IPos, DepClassTy::OPTIONAL, IsKnownNoUnwind)) { |
--- |
| 4701 |
UsedAssumedInformation |= !IsKnownNoUnwind; |
0 |
4701 |
UsedAssumedInformation |= !IsKnownNoUnwind; |
0 |
| 4702 |
} else { |
--- |
4702 |
} else { |
--- |
| 4703 |
AliveSuccessors.push_back(&II.getUnwindDest()->front()); |
0 |
4703 |
AliveSuccessors.push_back(&II.getUnwindDest()->front()); |
0 |
| 4704 |
} |
--- |
4704 |
} |
--- |
| 4705 |
} |
--- |
4705 |
} |
--- |
| 4706 |
return UsedAssumedInformation; |
0 |
4706 |
return UsedAssumedInformation; |
0 |
| 4707 |
} |
--- |
4707 |
} |
--- |
| 4708 |
|
--- |
4708 |
|
--- |
| 4709 |
static bool |
--- |
4709 |
static bool |
--- |
| 4710 |
identifyAliveSuccessors(Attributor &A, const BranchInst &BI, |
0 |
4710 |
identifyAliveSuccessors(Attributor &A, const BranchInst &BI, |
0 |
| 4711 |
AbstractAttribute &AA, |
--- |
4711 |
AbstractAttribute &AA, |
--- |
| 4712 |
SmallVectorImpl &AliveSuccessors) { |
--- |
4712 |
SmallVectorImpl &AliveSuccessors) { |
--- |
| 4713 |
bool UsedAssumedInformation = false; |
0 |
4713 |
bool UsedAssumedInformation = false; |
0 |
| 4714 |
if (BI.getNumSuccessors() == 1) { |
0 |
4714 |
if (BI.getNumSuccessors() == 1) { |
0 |
| 4715 |
AliveSuccessors.push_back(&BI.getSuccessor(0)->front()); |
0 |
4715 |
AliveSuccessors.push_back(&BI.getSuccessor(0)->front()); |
0 |
| 4716 |
} else { |
--- |
4716 |
} else { |
--- |
| 4717 |
std::optional C = |
--- |
4717 |
std::optional C = |
--- |
| 4718 |
A.getAssumedConstant(*BI.getCondition(), AA, UsedAssumedInformation); |
0 |
4718 |
A.getAssumedConstant(*BI.getCondition(), AA, UsedAssumedInformation); |
0 |
| 4719 |
if (!C || isa_and_nonnull(*C)) { |
0 |
4719 |
if (!C || isa_and_nonnull(*C)) { |
0 |
| 4720 |
// No value yet, assume both edges are dead. |
--- |
4720 |
// No value yet, assume both edges are dead. |
--- |
| 4721 |
} else if (isa_and_nonnull(*C)) { |
0 |
4721 |
} else if (isa_and_nonnull(*C)) { |
0 |
| 4722 |
const BasicBlock *SuccBB = |
--- |
4722 |
const BasicBlock *SuccBB = |
--- |
| 4723 |
BI.getSuccessor(1 - cast(*C)->getValue().getZExtValue()); |
0 |
4723 |
BI.getSuccessor(1 - cast(*C)->getValue().getZExtValue()); |
0 |
| 4724 |
AliveSuccessors.push_back(&SuccBB->front()); |
0 |
4724 |
AliveSuccessors.push_back(&SuccBB->front()); |
0 |
| 4725 |
} else { |
--- |
4725 |
} else { |
--- |
| 4726 |
AliveSuccessors.push_back(&BI.getSuccessor(0)->front()); |
0 |
4726 |
AliveSuccessors.push_back(&BI.getSuccessor(0)->front()); |
0 |
| 4727 |
AliveSuccessors.push_back(&BI.getSuccessor(1)->front()); |
0 |
4727 |
AliveSuccessors.push_back(&BI.getSuccessor(1)->front()); |
0 |
| 4728 |
UsedAssumedInformation = false; |
0 |
4728 |
UsedAssumedInformation = false; |
0 |
| 4729 |
} |
--- |
4729 |
} |
--- |
| 4730 |
} |
--- |
4730 |
} |
--- |
| 4731 |
return UsedAssumedInformation; |
0 |
4731 |
return UsedAssumedInformation; |
0 |
| 4732 |
} |
--- |
4732 |
} |
--- |
| 4733 |
|
--- |
4733 |
|
--- |
| 4734 |
static bool |
--- |
4734 |
static bool |
--- |
| 4735 |
identifyAliveSuccessors(Attributor &A, const SwitchInst &SI, |
0 |
4735 |
identifyAliveSuccessors(Attributor &A, const SwitchInst &SI, |
0 |
| 4736 |
AbstractAttribute &AA, |
--- |
4736 |
AbstractAttribute &AA, |
--- |
| 4737 |
SmallVectorImpl &AliveSuccessors) { |
--- |
4737 |
SmallVectorImpl &AliveSuccessors) { |
--- |
| 4738 |
bool UsedAssumedInformation = false; |
0 |
4738 |
bool UsedAssumedInformation = false; |
0 |
| 4739 |
std::optional C = |
--- |
4739 |
std::optional C = |
--- |
| 4740 |
A.getAssumedConstant(*SI.getCondition(), AA, UsedAssumedInformation); |
0 |
4740 |
A.getAssumedConstant(*SI.getCondition(), AA, UsedAssumedInformation); |
0 |
| 4741 |
if (!C || isa_and_nonnull(*C)) { |
0 |
4741 |
if (!C || isa_and_nonnull(*C)) { |
0 |
| 4742 |
// No value yet, assume all edges are dead. |
--- |
4742 |
// No value yet, assume all edges are dead. |
--- |
| 4743 |
} else if (isa_and_nonnull(*C)) { |
0 |
4743 |
} else if (isa_and_nonnull(*C)) { |
0 |
| 4744 |
for (const auto &CaseIt : SI.cases()) { |
0 |
4744 |
for (const auto &CaseIt : SI.cases()) { |
0 |
| 4745 |
if (CaseIt.getCaseValue() == *C) { |
0 |
4745 |
if (CaseIt.getCaseValue() == *C) { |
0 |
| 4746 |
AliveSuccessors.push_back(&CaseIt.getCaseSuccessor()->front()); |
0 |
4746 |
AliveSuccessors.push_back(&CaseIt.getCaseSuccessor()->front()); |
0 |
| 4747 |
return UsedAssumedInformation; |
0 |
4747 |
return UsedAssumedInformation; |
0 |
| 4748 |
} |
--- |
4748 |
} |
--- |
| 4749 |
} |
--- |
4749 |
} |
--- |
| 4750 |
AliveSuccessors.push_back(&SI.getDefaultDest()->front()); |
0 |
4750 |
AliveSuccessors.push_back(&SI.getDefaultDest()->front()); |
0 |
| 4751 |
return UsedAssumedInformation; |
0 |
4751 |
return UsedAssumedInformation; |
0 |
| 4752 |
} else { |
--- |
4752 |
} else { |
--- |
| 4753 |
for (const BasicBlock *SuccBB : successors(SI.getParent())) |
0 |
4753 |
for (const BasicBlock *SuccBB : successors(SI.getParent())) |
0 |
| 4754 |
AliveSuccessors.push_back(&SuccBB->front()); |
0 |
4754 |
AliveSuccessors.push_back(&SuccBB->front()); |
0 |
| 4755 |
} |
--- |
4755 |
} |
--- |
| 4756 |
return UsedAssumedInformation; |
0 |
4756 |
return UsedAssumedInformation; |
0 |
| 4757 |
} |
--- |
4757 |
} |
--- |
| 4758 |
|
--- |
4758 |
|
--- |
| 4759 |
ChangeStatus AAIsDeadFunction::updateImpl(Attributor &A) { |
0 |
4759 |
ChangeStatus AAIsDeadFunction::updateImpl(Attributor &A) { |
0 |
| 4760 |
ChangeStatus Change = ChangeStatus::UNCHANGED; |
0 |
4760 |
ChangeStatus Change = ChangeStatus::UNCHANGED; |
0 |
| 4761 |
|
--- |
4761 |
|
--- |
| 4762 |
if (AssumedLiveBlocks.empty()) { |
0 |
4762 |
if (AssumedLiveBlocks.empty()) { |
0 |
| 4763 |
if (isAssumedDeadInternalFunction(A)) |
0 |
4763 |
if (isAssumedDeadInternalFunction(A)) |
0 |
| 4764 |
return ChangeStatus::UNCHANGED; |
0 |
4764 |
return ChangeStatus::UNCHANGED; |
0 |
| 4765 |
|
--- |
4765 |
|
--- |
| 4766 |
Function *F = getAnchorScope(); |
0 |
4766 |
Function *F = getAnchorScope(); |
0 |
| 4767 |
ToBeExploredFrom.insert(&F->getEntryBlock().front()); |
0 |
4767 |
ToBeExploredFrom.insert(&F->getEntryBlock().front()); |
0 |
| 4768 |
assumeLive(A, F->getEntryBlock()); |
0 |
4768 |
assumeLive(A, F->getEntryBlock()); |
0 |
| 4769 |
Change = ChangeStatus::CHANGED; |
0 |
4769 |
Change = ChangeStatus::CHANGED; |
0 |
| 4770 |
} |
--- |
4770 |
} |
--- |
| 4771 |
|
--- |
4771 |
|
--- |
| 4772 |
LLVM_DEBUG(dbgs() << "[AAIsDead] Live [" << AssumedLiveBlocks.size() << "/" |
0 |
4772 |
LLVM_DEBUG(dbgs() << "[AAIsDead] Live [" << AssumedLiveBlocks.size() << "/" |
0 |
| 4773 |
<< getAnchorScope()->size() << "] BBs and " |
--- |
4773 |
<< getAnchorScope()->size() << "] BBs and " |
--- |
| 4774 |
<< ToBeExploredFrom.size() << " exploration points and " |
--- |
4774 |
<< ToBeExploredFrom.size() << " exploration points and " |
--- |
| 4775 |
<< KnownDeadEnds.size() << " known dead ends\n"); |
--- |
4775 |
<< KnownDeadEnds.size() << " known dead ends\n"); |
--- |
| 4776 |
|
--- |
4776 |
|
--- |
| 4777 |
// Copy and clear the list of instructions we need to explore from. It is |
--- |
4777 |
// Copy and clear the list of instructions we need to explore from. It is |
--- |
| 4778 |
// refilled with instructions the next update has to look at. |
--- |
4778 |
// refilled with instructions the next update has to look at. |
--- |
| 4779 |
SmallVector Worklist(ToBeExploredFrom.begin(), |
--- |
4779 |
SmallVector Worklist(ToBeExploredFrom.begin(), |
--- |
| 4780 |
ToBeExploredFrom.end()); |
0 |
4780 |
ToBeExploredFrom.end()); |
0 |
| 4781 |
decltype(ToBeExploredFrom) NewToBeExploredFrom; |
0 |
4781 |
decltype(ToBeExploredFrom) NewToBeExploredFrom; |
0 |
| 4782 |
|
--- |
4782 |
|
--- |
| 4783 |
SmallVector AliveSuccessors; |
0 |
4783 |
SmallVector AliveSuccessors; |
0 |
| 4784 |
while (!Worklist.empty()) { |
0 |
4784 |
while (!Worklist.empty()) { |
0 |
| 4785 |
const Instruction *I = Worklist.pop_back_val(); |
0 |
4785 |
const Instruction *I = Worklist.pop_back_val(); |
0 |
| 4786 |
LLVM_DEBUG(dbgs() << "[AAIsDead] Exploration inst: " << *I << "\n"); |
0 |
4786 |
LLVM_DEBUG(dbgs() << "[AAIsDead] Exploration inst: " << *I << "\n"); |
0 |
| 4787 |
|
--- |
4787 |
|
--- |
| 4788 |
// Fast forward for uninteresting instructions. We could look for UB here |
--- |
4788 |
// Fast forward for uninteresting instructions. We could look for UB here |
--- |
| 4789 |
// though. |
--- |
4789 |
// though. |
--- |
| 4790 |
while (!I->isTerminator() && !isa(I)) |
0 |
4790 |
while (!I->isTerminator() && !isa(I)) |
0 |
| 4791 |
I = I->getNextNode(); |
0 |
4791 |
I = I->getNextNode(); |
0 |
| 4792 |
|
--- |
4792 |
|
--- |
| 4793 |
AliveSuccessors.clear(); |
0 |
4793 |
AliveSuccessors.clear(); |
0 |
| 4794 |
|
--- |
4794 |
|
--- |
| 4795 |
bool UsedAssumedInformation = false; |
0 |
4795 |
bool UsedAssumedInformation = false; |
0 |
| 4796 |
switch (I->getOpcode()) { |
0 |
4796 |
switch (I->getOpcode()) { |
0 |
| 4797 |
// TODO: look for (assumed) UB to backwards propagate "deadness". |
--- |
4797 |
// TODO: look for (assumed) UB to backwards propagate "deadness". |
--- |
| 4798 |
default: |
0 |
4798 |
default: |
0 |
| 4799 |
assert(I->isTerminator() && |
0 |
4799 |
assert(I->isTerminator() && |
0 |
| 4800 |
"Expected non-terminators to be handled already!"); |
--- |
4800 |
"Expected non-terminators to be handled already!"); |
--- |
| 4801 |
for (const BasicBlock *SuccBB : successors(I->getParent())) |
0 |
4801 |
for (const BasicBlock *SuccBB : successors(I->getParent())) |
0 |
| 4802 |
AliveSuccessors.push_back(&SuccBB->front()); |
0 |
4802 |
AliveSuccessors.push_back(&SuccBB->front()); |
0 |
| 4803 |
break; |
0 |
4803 |
break; |
0 |
| 4804 |
case Instruction::Call: |
0 |
4804 |
case Instruction::Call: |
0 |
| 4805 |
UsedAssumedInformation = identifyAliveSuccessors(A, cast(*I), |
0 |
4805 |
UsedAssumedInformation = identifyAliveSuccessors(A, cast(*I), |
0 |
| 4806 |
*this, AliveSuccessors); |
--- |
4806 |
*this, AliveSuccessors); |
--- |
| 4807 |
break; |
0 |
4807 |
break; |
0 |
| 4808 |
case Instruction::Invoke: |
0 |
4808 |
case Instruction::Invoke: |
0 |
| 4809 |
UsedAssumedInformation = identifyAliveSuccessors(A, cast(*I), |
0 |
4809 |
UsedAssumedInformation = identifyAliveSuccessors(A, cast(*I), |
0 |
| 4810 |
*this, AliveSuccessors); |
--- |
4810 |
*this, AliveSuccessors); |
--- |
| 4811 |
break; |
0 |
4811 |
break; |
0 |
| 4812 |
case Instruction::Br: |
0 |
4812 |
case Instruction::Br: |
0 |
| 4813 |
UsedAssumedInformation = identifyAliveSuccessors(A, cast(*I), |
0 |
4813 |
UsedAssumedInformation = identifyAliveSuccessors(A, cast(*I), |
0 |
| 4814 |
*this, AliveSuccessors); |
--- |
4814 |
*this, AliveSuccessors); |
--- |
| 4815 |
break; |
0 |
4815 |
break; |
0 |
| 4816 |
case Instruction::Switch: |
0 |
4816 |
case Instruction::Switch: |
0 |
| 4817 |
UsedAssumedInformation = identifyAliveSuccessors(A, cast(*I), |
0 |
4817 |
UsedAssumedInformation = identifyAliveSuccessors(A, cast(*I), |
0 |
| 4818 |
*this, AliveSuccessors); |
--- |
4818 |
*this, AliveSuccessors); |
--- |
| 4819 |
break; |
0 |
4819 |
break; |
0 |
| 4820 |
} |
--- |
4820 |
} |
--- |
| 4821 |
|
--- |
4821 |
|
--- |
| 4822 |
if (UsedAssumedInformation) { |
0 |
4822 |
if (UsedAssumedInformation) { |
0 |
| 4823 |
NewToBeExploredFrom.insert(I); |
0 |
4823 |
NewToBeExploredFrom.insert(I); |
0 |
| 4824 |
} else if (AliveSuccessors.empty() || |
0 |
4824 |
} else if (AliveSuccessors.empty() || |
0 |
| 4825 |
(I->isTerminator() && |
0 |
4825 |
(I->isTerminator() && |
0 |
| 4826 |
AliveSuccessors.size() < I->getNumSuccessors())) { |
0 |
4826 |
AliveSuccessors.size() < I->getNumSuccessors())) { |
0 |
| 4827 |
if (KnownDeadEnds.insert(I)) |
0 |
4827 |
if (KnownDeadEnds.insert(I)) |
0 |
| 4828 |
Change = ChangeStatus::CHANGED; |
0 |
4828 |
Change = ChangeStatus::CHANGED; |
0 |
| 4829 |
} |
--- |
4829 |
} |
--- |
| 4830 |
|
--- |
4830 |
|
--- |
| 4831 |
LLVM_DEBUG(dbgs() << "[AAIsDead] #AliveSuccessors: " |
0 |
4831 |
LLVM_DEBUG(dbgs() << "[AAIsDead] #AliveSuccessors: " |
0 |
| 4832 |
<< AliveSuccessors.size() << " UsedAssumedInformation: " |
--- |
4832 |
<< AliveSuccessors.size() << " UsedAssumedInformation: " |
--- |
| 4833 |
<< UsedAssumedInformation << "\n"); |
--- |
4833 |
<< UsedAssumedInformation << "\n"); |
--- |
| 4834 |
|
--- |
4834 |
|
--- |
| 4835 |
for (const Instruction *AliveSuccessor : AliveSuccessors) { |
0 |
4835 |
for (const Instruction *AliveSuccessor : AliveSuccessors) { |
0 |
| 4836 |
if (!I->isTerminator()) { |
0 |
4836 |
if (!I->isTerminator()) { |
0 |
| 4837 |
assert(AliveSuccessors.size() == 1 && |
0 |
4837 |
assert(AliveSuccessors.size() == 1 && |
0 |
| 4838 |
"Non-terminator expected to have a single successor!"); |
--- |
4838 |
"Non-terminator expected to have a single successor!"); |
--- |
| 4839 |
Worklist.push_back(AliveSuccessor); |
0 |
4839 |
Worklist.push_back(AliveSuccessor); |
0 |
| 4840 |
} else { |
--- |
4840 |
} else { |
--- |
| 4841 |
// record the assumed live edge |
--- |
4841 |
// record the assumed live edge |
--- |
| 4842 |
auto Edge = std::make_pair(I->getParent(), AliveSuccessor->getParent()); |
0 |
4842 |
auto Edge = std::make_pair(I->getParent(), AliveSuccessor->getParent()); |
0 |
| 4843 |
if (AssumedLiveEdges.insert(Edge).second) |
0 |
4843 |
if (AssumedLiveEdges.insert(Edge).second) |
0 |
| 4844 |
Change = ChangeStatus::CHANGED; |
0 |
4844 |
Change = ChangeStatus::CHANGED; |
0 |
| 4845 |
if (assumeLive(A, *AliveSuccessor->getParent())) |
0 |
4845 |
if (assumeLive(A, *AliveSuccessor->getParent())) |
0 |
| 4846 |
Worklist.push_back(AliveSuccessor); |
0 |
4846 |
Worklist.push_back(AliveSuccessor); |
0 |
| 4847 |
} |
--- |
4847 |
} |
--- |
| 4848 |
} |
--- |
4848 |
} |
--- |
| 4849 |
} |
--- |
4849 |
} |
--- |
| 4850 |
|
--- |
4850 |
|
--- |
| 4851 |
// Check if the content of ToBeExploredFrom changed, ignore the order. |
--- |
4851 |
// Check if the content of ToBeExploredFrom changed, ignore the order. |
--- |
| 4852 |
if (NewToBeExploredFrom.size() != ToBeExploredFrom.size() || |
0 |
4852 |
if (NewToBeExploredFrom.size() != ToBeExploredFrom.size() || |
0 |
| 4853 |
llvm::any_of(NewToBeExploredFrom, [&](const Instruction *I) { |
0 |
4853 |
llvm::any_of(NewToBeExploredFrom, [&](const Instruction *I) { |
0 |
| 4854 |
return !ToBeExploredFrom.count(I); |
0 |
4854 |
return !ToBeExploredFrom.count(I); |
0 |
| 4855 |
})) { |
--- |
4855 |
})) { |
--- |
| 4856 |
Change = ChangeStatus::CHANGED; |
0 |
4856 |
Change = ChangeStatus::CHANGED; |
0 |
| 4857 |
ToBeExploredFrom = std::move(NewToBeExploredFrom); |
0 |
4857 |
ToBeExploredFrom = std::move(NewToBeExploredFrom); |
0 |
| 4858 |
} |
--- |
4858 |
} |
--- |
| 4859 |
|
--- |
4859 |
|
--- |
| 4860 |
// If we know everything is live there is no need to query for liveness. |
--- |
4860 |
// If we know everything is live there is no need to query for liveness. |
--- |
| 4861 |
// Instead, indicating a pessimistic fixpoint will cause the state to be |
--- |
4861 |
// Instead, indicating a pessimistic fixpoint will cause the state to be |
--- |
| 4862 |
// "invalid" and all queries to be answered conservatively without lookups. |
--- |
4862 |
// "invalid" and all queries to be answered conservatively without lookups. |
--- |
| 4863 |
// To be in this state we have to (1) finished the exploration and (3) not |
--- |
4863 |
// To be in this state we have to (1) finished the exploration and (3) not |
--- |
| 4864 |
// discovered any non-trivial dead end and (2) not ruled unreachable code |
--- |
4864 |
// discovered any non-trivial dead end and (2) not ruled unreachable code |
--- |
| 4865 |
// dead. |
--- |
4865 |
// dead. |
--- |
| 4866 |
if (ToBeExploredFrom.empty() && |
0 |
4866 |
if (ToBeExploredFrom.empty() && |
0 |
| 4867 |
getAnchorScope()->size() == AssumedLiveBlocks.size() && |
0 |
4867 |
getAnchorScope()->size() == AssumedLiveBlocks.size() && |
0 |
| 4868 |
llvm::all_of(KnownDeadEnds, [](const Instruction *DeadEndI) { |
0 |
4868 |
llvm::all_of(KnownDeadEnds, [](const Instruction *DeadEndI) { |
0 |
| 4869 |
return DeadEndI->isTerminator() && DeadEndI->getNumSuccessors() == 0; |
0 |
4869 |
return DeadEndI->isTerminator() && DeadEndI->getNumSuccessors() == 0; |
0 |
| 4870 |
})) |
--- |
4870 |
})) |
--- |
| 4871 |
return indicatePessimisticFixpoint(); |
0 |
4871 |
return indicatePessimisticFixpoint(); |
0 |
| 4872 |
return Change; |
0 |
4872 |
return Change; |
0 |
| 4873 |
} |
0 |
4873 |
} |
0 |
| 4874 |
|
--- |
4874 |
|
--- |
| 4875 |
/// Liveness information for a call sites. |
--- |
4875 |
/// Liveness information for a call sites. |
--- |
| 4876 |
struct AAIsDeadCallSite final : AAIsDeadFunction { |
--- |
4876 |
struct AAIsDeadCallSite final : AAIsDeadFunction { |
--- |
| 4877 |
AAIsDeadCallSite(const IRPosition &IRP, Attributor &A) |
0 |
4877 |
AAIsDeadCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 4878 |
: AAIsDeadFunction(IRP, A) {} |
0 |
4878 |
: AAIsDeadFunction(IRP, A) {} |
0 |
| 4879 |
|
--- |
4879 |
|
--- |
| 4880 |
/// See AbstractAttribute::initialize(...). |
--- |
4880 |
/// See AbstractAttribute::initialize(...). |
--- |
| 4881 |
void initialize(Attributor &A) override { |
0 |
4881 |
void initialize(Attributor &A) override { |
0 |
| 4882 |
// TODO: Once we have call site specific value information we can provide |
--- |
4882 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 4883 |
// call site specific liveness information and then it makes |
--- |
4883 |
// call site specific liveness information and then it makes |
--- |
| 4884 |
// sense to specialize attributes for call sites instead of |
--- |
4884 |
// sense to specialize attributes for call sites instead of |
--- |
| 4885 |
// redirecting requests to the callee. |
--- |
4885 |
// redirecting requests to the callee. |
--- |
| 4886 |
llvm_unreachable("Abstract attributes for liveness are not " |
0 |
4886 |
llvm_unreachable("Abstract attributes for liveness are not " |
0 |
| 4887 |
"supported for call sites yet!"); |
--- |
4887 |
"supported for call sites yet!"); |
--- |
| 4888 |
} |
--- |
4888 |
} |
--- |
| 4889 |
|
--- |
4889 |
|
--- |
| 4890 |
/// See AbstractAttribute::updateImpl(...). |
--- |
4890 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 4891 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
4891 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 4892 |
return indicatePessimisticFixpoint(); |
0 |
4892 |
return indicatePessimisticFixpoint(); |
0 |
| 4893 |
} |
--- |
4893 |
} |
--- |
| 4894 |
|
--- |
4894 |
|
--- |
| 4895 |
/// See AbstractAttribute::trackStatistics() |
--- |
4895 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 4896 |
void trackStatistics() const override {} |
0 |
4896 |
void trackStatistics() const override {} |
0 |
| 4897 |
}; |
--- |
4897 |
}; |
--- |
| 4898 |
} // namespace |
--- |
4898 |
} // namespace |
--- |
| 4899 |
|
--- |
4899 |
|
--- |
| 4900 |
/// -------------------- Dereferenceable Argument Attribute -------------------- |
--- |
4900 |
/// -------------------- Dereferenceable Argument Attribute -------------------- |
--- |
| 4901 |
|
--- |
4901 |
|
--- |
| 4902 |
namespace { |
--- |
4902 |
namespace { |
--- |
| 4903 |
struct AADereferenceableImpl : AADereferenceable { |
--- |
4903 |
struct AADereferenceableImpl : AADereferenceable { |
--- |
| 4904 |
AADereferenceableImpl(const IRPosition &IRP, Attributor &A) |
0 |
4904 |
AADereferenceableImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 4905 |
: AADereferenceable(IRP, A) {} |
0 |
4905 |
: AADereferenceable(IRP, A) {} |
0 |
| 4906 |
using StateType = DerefState; |
--- |
4906 |
using StateType = DerefState; |
--- |
| 4907 |
|
--- |
4907 |
|
--- |
| 4908 |
/// See AbstractAttribute::initialize(...). |
--- |
4908 |
/// See AbstractAttribute::initialize(...). |
--- |
| 4909 |
void initialize(Attributor &A) override { |
0 |
4909 |
void initialize(Attributor &A) override { |
0 |
| 4910 |
Value &V = *getAssociatedValue().stripPointerCasts(); |
0 |
4910 |
Value &V = *getAssociatedValue().stripPointerCasts(); |
0 |
| 4911 |
SmallVector Attrs; |
0 |
4911 |
SmallVector Attrs; |
0 |
| 4912 |
A.getAttrs(getIRPosition(), |
0 |
4912 |
A.getAttrs(getIRPosition(), |
0 |
| 4913 |
{Attribute::Dereferenceable, Attribute::DereferenceableOrNull}, |
--- |
4913 |
{Attribute::Dereferenceable, Attribute::DereferenceableOrNull}, |
--- |
| 4914 |
Attrs, /* IgnoreSubsumingPositions */ false); |
--- |
4914 |
Attrs, /* IgnoreSubsumingPositions */ false); |
--- |
| 4915 |
for (const Attribute &Attr : Attrs) |
0 |
4915 |
for (const Attribute &Attr : Attrs) |
0 |
| 4916 |
takeKnownDerefBytesMaximum(Attr.getValueAsInt()); |
0 |
4916 |
takeKnownDerefBytesMaximum(Attr.getValueAsInt()); |
0 |
| 4917 |
|
--- |
4917 |
|
--- |
| 4918 |
// Ensure we initialize the non-null AA (if necessary). |
--- |
4918 |
// Ensure we initialize the non-null AA (if necessary). |
--- |
| 4919 |
bool IsKnownNonNull; |
--- |
4919 |
bool IsKnownNonNull; |
--- |
| 4920 |
AA::hasAssumedIRAttr( |
0 |
4920 |
AA::hasAssumedIRAttr( |
0 |
| 4921 |
A, this, getIRPosition(), DepClassTy::OPTIONAL, IsKnownNonNull); |
0 |
4921 |
A, this, getIRPosition(), DepClassTy::OPTIONAL, IsKnownNonNull); |
0 |
| 4922 |
|
--- |
4922 |
|
--- |
| 4923 |
bool CanBeNull, CanBeFreed; |
--- |
4923 |
bool CanBeNull, CanBeFreed; |
--- |
| 4924 |
takeKnownDerefBytesMaximum(V.getPointerDereferenceableBytes( |
0 |
4924 |
takeKnownDerefBytesMaximum(V.getPointerDereferenceableBytes( |
0 |
| 4925 |
A.getDataLayout(), CanBeNull, CanBeFreed)); |
--- |
4925 |
A.getDataLayout(), CanBeNull, CanBeFreed)); |
--- |
| 4926 |
|
--- |
4926 |
|
--- |
| 4927 |
if (Instruction *CtxI = getCtxI()) |
0 |
4927 |
if (Instruction *CtxI = getCtxI()) |
0 |
| 4928 |
followUsesInMBEC(*this, A, getState(), *CtxI); |
0 |
4928 |
followUsesInMBEC(*this, A, getState(), *CtxI); |
0 |
| 4929 |
} |
0 |
4929 |
} |
0 |
| 4930 |
|
--- |
4930 |
|
--- |
| 4931 |
/// See AbstractAttribute::getState() |
--- |
4931 |
/// See AbstractAttribute::getState() |
--- |
| 4932 |
/// { |
--- |
4932 |
/// { |
--- |
| 4933 |
StateType &getState() override { return *this; } |
0 |
4933 |
StateType &getState() override { return *this; } |
0 |
| 4934 |
const StateType &getState() const override { return *this; } |
0 |
4934 |
const StateType &getState() const override { return *this; } |
0 |
| 4935 |
/// } |
--- |
4935 |
/// } |
--- |
| 4936 |
|
--- |
4936 |
|
--- |
| 4937 |
/// Helper function for collecting accessed bytes in must-be-executed-context |
--- |
4937 |
/// Helper function for collecting accessed bytes in must-be-executed-context |
--- |
| 4938 |
void addAccessedBytesForUse(Attributor &A, const Use *U, const Instruction *I, |
0 |
4938 |
void addAccessedBytesForUse(Attributor &A, const Use *U, const Instruction *I, |
0 |
| 4939 |
DerefState &State) { |
--- |
4939 |
DerefState &State) { |
--- |
| 4940 |
const Value *UseV = U->get(); |
0 |
4940 |
const Value *UseV = U->get(); |
0 |
| 4941 |
if (!UseV->getType()->isPointerTy()) |
0 |
4941 |
if (!UseV->getType()->isPointerTy()) |
0 |
| 4942 |
return; |
0 |
4942 |
return; |
0 |
| 4943 |
|
--- |
4943 |
|
--- |
| 4944 |
std::optional Loc = MemoryLocation::getOrNone(I); |
0 |
4944 |
std::optional Loc = MemoryLocation::getOrNone(I); |
0 |
| 4945 |
if (!Loc || Loc->Ptr != UseV || !Loc->Size.isPrecise() || I->isVolatile()) |
0 |
4945 |
if (!Loc || Loc->Ptr != UseV || !Loc->Size.isPrecise() || I->isVolatile()) |
0 |
| 4946 |
return; |
0 |
4946 |
return; |
0 |
| 4947 |
|
--- |
4947 |
|
--- |
| 4948 |
int64_t Offset; |
--- |
4948 |
int64_t Offset; |
--- |
| 4949 |
const Value *Base = GetPointerBaseWithConstantOffset( |
0 |
4949 |
const Value *Base = GetPointerBaseWithConstantOffset( |
0 |
| 4950 |
Loc->Ptr, Offset, A.getDataLayout(), /*AllowNonInbounds*/ true); |
0 |
4950 |
Loc->Ptr, Offset, A.getDataLayout(), /*AllowNonInbounds*/ true); |
0 |
| 4951 |
if (Base && Base == &getAssociatedValue()) |
0 |
4951 |
if (Base && Base == &getAssociatedValue()) |
0 |
| 4952 |
State.addAccessedBytes(Offset, Loc->Size.getValue()); |
0 |
4952 |
State.addAccessedBytes(Offset, Loc->Size.getValue()); |
0 |
| 4953 |
} |
--- |
4953 |
} |
--- |
| 4954 |
|
--- |
4954 |
|
--- |
| 4955 |
/// See followUsesInMBEC |
--- |
4955 |
/// See followUsesInMBEC |
--- |
| 4956 |
bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I, |
0 |
4956 |
bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I, |
0 |
| 4957 |
AADereferenceable::StateType &State) { |
--- |
4957 |
AADereferenceable::StateType &State) { |
--- |
| 4958 |
bool IsNonNull = false; |
0 |
4958 |
bool IsNonNull = false; |
0 |
| 4959 |
bool TrackUse = false; |
0 |
4959 |
bool TrackUse = false; |
0 |
| 4960 |
int64_t DerefBytes = getKnownNonNullAndDerefBytesForUse( |
0 |
4960 |
int64_t DerefBytes = getKnownNonNullAndDerefBytesForUse( |
0 |
| 4961 |
A, *this, getAssociatedValue(), U, I, IsNonNull, TrackUse); |
--- |
4961 |
A, *this, getAssociatedValue(), U, I, IsNonNull, TrackUse); |
--- |
| 4962 |
LLVM_DEBUG(dbgs() << "[AADereferenceable] Deref bytes: " << DerefBytes |
0 |
4962 |
LLVM_DEBUG(dbgs() << "[AADereferenceable] Deref bytes: " << DerefBytes |
0 |
| 4963 |
<< " for instruction " << *I << "\n"); |
--- |
4963 |
<< " for instruction " << *I << "\n"); |
--- |
| 4964 |
|
--- |
4964 |
|
--- |
| 4965 |
addAccessedBytesForUse(A, U, I, State); |
0 |
4965 |
addAccessedBytesForUse(A, U, I, State); |
0 |
| 4966 |
State.takeKnownDerefBytesMaximum(DerefBytes); |
0 |
4966 |
State.takeKnownDerefBytesMaximum(DerefBytes); |
0 |
| 4967 |
return TrackUse; |
0 |
4967 |
return TrackUse; |
0 |
| 4968 |
} |
--- |
4968 |
} |
--- |
| 4969 |
|
--- |
4969 |
|
--- |
| 4970 |
/// See AbstractAttribute::manifest(...). |
--- |
4970 |
/// See AbstractAttribute::manifest(...). |
--- |
| 4971 |
ChangeStatus manifest(Attributor &A) override { |
0 |
4971 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 4972 |
ChangeStatus Change = AADereferenceable::manifest(A); |
0 |
4972 |
ChangeStatus Change = AADereferenceable::manifest(A); |
0 |
| 4973 |
bool IsKnownNonNull; |
--- |
4973 |
bool IsKnownNonNull; |
--- |
| 4974 |
bool IsAssumedNonNull = AA::hasAssumedIRAttr( |
0 |
4974 |
bool IsAssumedNonNull = AA::hasAssumedIRAttr( |
0 |
| 4975 |
A, this, getIRPosition(), DepClassTy::NONE, IsKnownNonNull); |
0 |
4975 |
A, this, getIRPosition(), DepClassTy::NONE, IsKnownNonNull); |
0 |
| 4976 |
if (IsAssumedNonNull && |
0 |
4976 |
if (IsAssumedNonNull && |
0 |
| 4977 |
A.hasAttr(getIRPosition(), Attribute::DereferenceableOrNull)) { |
0 |
4977 |
A.hasAttr(getIRPosition(), Attribute::DereferenceableOrNull)) { |
0 |
| 4978 |
A.removeAttrs(getIRPosition(), {Attribute::DereferenceableOrNull}); |
0 |
4978 |
A.removeAttrs(getIRPosition(), {Attribute::DereferenceableOrNull}); |
0 |
| 4979 |
return ChangeStatus::CHANGED; |
0 |
4979 |
return ChangeStatus::CHANGED; |
0 |
| 4980 |
} |
--- |
4980 |
} |
--- |
| 4981 |
return Change; |
0 |
4981 |
return Change; |
0 |
| 4982 |
} |
--- |
4982 |
} |
--- |
| 4983 |
|
--- |
4983 |
|
--- |
| 4984 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
4984 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
| 4985 |
SmallVectorImpl &Attrs) const override { |
--- |
4985 |
SmallVectorImpl &Attrs) const override { |
--- |
| 4986 |
// TODO: Add *_globally support |
--- |
4986 |
// TODO: Add *_globally support |
--- |
| 4987 |
bool IsKnownNonNull; |
--- |
4987 |
bool IsKnownNonNull; |
--- |
| 4988 |
bool IsAssumedNonNull = AA::hasAssumedIRAttr( |
0 |
4988 |
bool IsAssumedNonNull = AA::hasAssumedIRAttr( |
0 |
| 4989 |
A, this, getIRPosition(), DepClassTy::NONE, IsKnownNonNull); |
--- |
4989 |
A, this, getIRPosition(), DepClassTy::NONE, IsKnownNonNull); |
--- |
| 4990 |
if (IsAssumedNonNull) |
0 |
4990 |
if (IsAssumedNonNull) |
0 |
| 4991 |
Attrs.emplace_back(Attribute::getWithDereferenceableBytes( |
0 |
4991 |
Attrs.emplace_back(Attribute::getWithDereferenceableBytes( |
0 |
| 4992 |
Ctx, getAssumedDereferenceableBytes())); |
0 |
4992 |
Ctx, getAssumedDereferenceableBytes())); |
0 |
| 4993 |
else |
--- |
4993 |
else |
--- |
| 4994 |
Attrs.emplace_back(Attribute::getWithDereferenceableOrNullBytes( |
0 |
4994 |
Attrs.emplace_back(Attribute::getWithDereferenceableOrNullBytes( |
0 |
| 4995 |
Ctx, getAssumedDereferenceableBytes())); |
0 |
4995 |
Ctx, getAssumedDereferenceableBytes())); |
0 |
| 4996 |
} |
0 |
4996 |
} |
0 |
| 4997 |
|
--- |
4997 |
|
--- |
| 4998 |
/// See AbstractAttribute::getAsStr(). |
--- |
4998 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 4999 |
const std::string getAsStr(Attributor *A) const override { |
0 |
4999 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 5000 |
if (!getAssumedDereferenceableBytes()) |
0 |
5000 |
if (!getAssumedDereferenceableBytes()) |
0 |
| 5001 |
return "unknown-dereferenceable"; |
0 |
5001 |
return "unknown-dereferenceable"; |
0 |
| 5002 |
bool IsKnownNonNull; |
--- |
5002 |
bool IsKnownNonNull; |
--- |
| 5003 |
bool IsAssumedNonNull = false; |
0 |
5003 |
bool IsAssumedNonNull = false; |
0 |
| 5004 |
if (A) |
0 |
5004 |
if (A) |
0 |
| 5005 |
IsAssumedNonNull = AA::hasAssumedIRAttr( |
0 |
5005 |
IsAssumedNonNull = AA::hasAssumedIRAttr( |
0 |
| 5006 |
*A, this, getIRPosition(), DepClassTy::NONE, IsKnownNonNull); |
--- |
5006 |
*A, this, getIRPosition(), DepClassTy::NONE, IsKnownNonNull); |
--- |
| 5007 |
return std::string("dereferenceable") + |
0 |
5007 |
return std::string("dereferenceable") + |
0 |
| 5008 |
(IsAssumedNonNull ? "" : "_or_null") + |
0 |
5008 |
(IsAssumedNonNull ? "" : "_or_null") + |
0 |
| 5009 |
(isAssumedGlobal() ? "_globally" : "") + "<" + |
0 |
5009 |
(isAssumedGlobal() ? "_globally" : "") + "<" + |
0 |
| 5010 |
std::to_string(getKnownDereferenceableBytes()) + "-" + |
0 |
5010 |
std::to_string(getKnownDereferenceableBytes()) + "-" + |
0 |
| 5011 |
std::to_string(getAssumedDereferenceableBytes()) + ">" + |
0 |
5011 |
std::to_string(getAssumedDereferenceableBytes()) + ">" + |
0 |
| 5012 |
(!A ? " [non-null is unknown]" : ""); |
0 |
5012 |
(!A ? " [non-null is unknown]" : ""); |
0 |
| 5013 |
} |
--- |
5013 |
} |
--- |
| 5014 |
}; |
--- |
5014 |
}; |
--- |
| 5015 |
|
--- |
5015 |
|
--- |
| 5016 |
/// Dereferenceable attribute for a floating value. |
--- |
5016 |
/// Dereferenceable attribute for a floating value. |
--- |
| 5017 |
struct AADereferenceableFloating : AADereferenceableImpl { |
--- |
5017 |
struct AADereferenceableFloating : AADereferenceableImpl { |
--- |
| 5018 |
AADereferenceableFloating(const IRPosition &IRP, Attributor &A) |
0 |
5018 |
AADereferenceableFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 5019 |
: AADereferenceableImpl(IRP, A) {} |
0 |
5019 |
: AADereferenceableImpl(IRP, A) {} |
0 |
| 5020 |
|
--- |
5020 |
|
--- |
| 5021 |
/// See AbstractAttribute::updateImpl(...). |
--- |
5021 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 5022 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
5022 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 5023 |
bool Stripped; |
--- |
5023 |
bool Stripped; |
--- |
| 5024 |
bool UsedAssumedInformation = false; |
0 |
5024 |
bool UsedAssumedInformation = false; |
0 |
| 5025 |
SmallVector Values; |
0 |
5025 |
SmallVector Values; |
0 |
| 5026 |
if (!A.getAssumedSimplifiedValues(getIRPosition(), *this, Values, |
0 |
5026 |
if (!A.getAssumedSimplifiedValues(getIRPosition(), *this, Values, |
0 |
| 5027 |
AA::AnyScope, UsedAssumedInformation)) { |
--- |
5027 |
AA::AnyScope, UsedAssumedInformation)) { |
--- |
| 5028 |
Values.push_back({getAssociatedValue(), getCtxI()}); |
0 |
5028 |
Values.push_back({getAssociatedValue(), getCtxI()}); |
0 |
| 5029 |
Stripped = false; |
0 |
5029 |
Stripped = false; |
0 |
| 5030 |
} else { |
--- |
5030 |
} else { |
--- |
| 5031 |
Stripped = Values.size() != 1 || |
0 |
5031 |
Stripped = Values.size() != 1 || |
0 |
| 5032 |
Values.front().getValue() != &getAssociatedValue(); |
0 |
5032 |
Values.front().getValue() != &getAssociatedValue(); |
0 |
| 5033 |
} |
--- |
5033 |
} |
--- |
| 5034 |
|
--- |
5034 |
|
--- |
| 5035 |
const DataLayout &DL = A.getDataLayout(); |
0 |
5035 |
const DataLayout &DL = A.getDataLayout(); |
0 |
| 5036 |
DerefState T; |
0 |
5036 |
DerefState T; |
0 |
| 5037 |
|
--- |
5037 |
|
--- |
| 5038 |
auto VisitValueCB = [&](const Value &V) -> bool { |
0 |
5038 |
auto VisitValueCB = [&](const Value &V) -> bool { |
0 |
| 5039 |
unsigned IdxWidth = |
--- |
5039 |
unsigned IdxWidth = |
--- |
| 5040 |
DL.getIndexSizeInBits(V.getType()->getPointerAddressSpace()); |
0 |
5040 |
DL.getIndexSizeInBits(V.getType()->getPointerAddressSpace()); |
0 |
| 5041 |
APInt Offset(IdxWidth, 0); |
0 |
5041 |
APInt Offset(IdxWidth, 0); |
0 |
| 5042 |
const Value *Base = stripAndAccumulateOffsets( |
0 |
5042 |
const Value *Base = stripAndAccumulateOffsets( |
0 |
| 5043 |
A, *this, &V, DL, Offset, /* GetMinOffset */ false, |
0 |
5043 |
A, *this, &V, DL, Offset, /* GetMinOffset */ false, |
0 |
| 5044 |
/* AllowNonInbounds */ true); |
--- |
5044 |
/* AllowNonInbounds */ true); |
--- |
| 5045 |
|
--- |
5045 |
|
--- |
| 5046 |
const auto *AA = A.getAAFor( |
0 |
5046 |
const auto *AA = A.getAAFor( |
0 |
| 5047 |
*this, IRPosition::value(*Base), DepClassTy::REQUIRED); |
0 |
5047 |
*this, IRPosition::value(*Base), DepClassTy::REQUIRED); |
0 |
| 5048 |
int64_t DerefBytes = 0; |
0 |
5048 |
int64_t DerefBytes = 0; |
0 |
| 5049 |
if (!AA || (!Stripped && this == AA)) { |
0 |
5049 |
if (!AA || (!Stripped && this == AA)) { |
0 |
| 5050 |
// Use IR information if we did not strip anything. |
--- |
5050 |
// Use IR information if we did not strip anything. |
--- |
| 5051 |
// TODO: track globally. |
--- |
5051 |
// TODO: track globally. |
--- |
| 5052 |
bool CanBeNull, CanBeFreed; |
--- |
5052 |
bool CanBeNull, CanBeFreed; |
--- |
| 5053 |
DerefBytes = |
0 |
5053 |
DerefBytes = |
0 |
| 5054 |
Base->getPointerDereferenceableBytes(DL, CanBeNull, CanBeFreed); |
0 |
5054 |
Base->getPointerDereferenceableBytes(DL, CanBeNull, CanBeFreed); |
0 |
| 5055 |
T.GlobalState.indicatePessimisticFixpoint(); |
0 |
5055 |
T.GlobalState.indicatePessimisticFixpoint(); |
0 |
| 5056 |
} else { |
0 |
5056 |
} else { |
0 |
| 5057 |
const DerefState &DS = AA->getState(); |
0 |
5057 |
const DerefState &DS = AA->getState(); |
0 |
| 5058 |
DerefBytes = DS.DerefBytesState.getAssumed(); |
0 |
5058 |
DerefBytes = DS.DerefBytesState.getAssumed(); |
0 |
| 5059 |
T.GlobalState &= DS.GlobalState; |
0 |
5059 |
T.GlobalState &= DS.GlobalState; |
0 |
| 5060 |
} |
--- |
5060 |
} |
--- |
| 5061 |
|
--- |
5061 |
|
--- |
| 5062 |
// For now we do not try to "increase" dereferenceability due to negative |
--- |
5062 |
// For now we do not try to "increase" dereferenceability due to negative |
--- |
| 5063 |
// indices as we first have to come up with code to deal with loops and |
--- |
5063 |
// indices as we first have to come up with code to deal with loops and |
--- |
| 5064 |
// for overflows of the dereferenceable bytes. |
--- |
5064 |
// for overflows of the dereferenceable bytes. |
--- |
| 5065 |
int64_t OffsetSExt = Offset.getSExtValue(); |
0 |
5065 |
int64_t OffsetSExt = Offset.getSExtValue(); |
0 |
| 5066 |
if (OffsetSExt < 0) |
0 |
5066 |
if (OffsetSExt < 0) |
0 |
| 5067 |
OffsetSExt = 0; |
0 |
5067 |
OffsetSExt = 0; |
0 |
| 5068 |
|
--- |
5068 |
|
--- |
| 5069 |
T.takeAssumedDerefBytesMinimum( |
0 |
5069 |
T.takeAssumedDerefBytesMinimum( |
0 |
| 5070 |
std::max(int64_t(0), DerefBytes - OffsetSExt)); |
0 |
5070 |
std::max(int64_t(0), DerefBytes - OffsetSExt)); |
0 |
| 5071 |
|
--- |
5071 |
|
--- |
| 5072 |
if (this == AA) { |
0 |
5072 |
if (this == AA) { |
0 |
| 5073 |
if (!Stripped) { |
0 |
5073 |
if (!Stripped) { |
0 |
| 5074 |
// If nothing was stripped IR information is all we got. |
--- |
5074 |
// If nothing was stripped IR information is all we got. |
--- |
| 5075 |
T.takeKnownDerefBytesMaximum( |
0 |
5075 |
T.takeKnownDerefBytesMaximum( |
0 |
| 5076 |
std::max(int64_t(0), DerefBytes - OffsetSExt)); |
0 |
5076 |
std::max(int64_t(0), DerefBytes - OffsetSExt)); |
0 |
| 5077 |
T.indicatePessimisticFixpoint(); |
0 |
5077 |
T.indicatePessimisticFixpoint(); |
0 |
| 5078 |
} else if (OffsetSExt > 0) { |
0 |
5078 |
} else if (OffsetSExt > 0) { |
0 |
| 5079 |
// If something was stripped but there is circular reasoning we look |
--- |
5079 |
// If something was stripped but there is circular reasoning we look |
--- |
| 5080 |
// for the offset. If it is positive we basically decrease the |
--- |
5080 |
// for the offset. If it is positive we basically decrease the |
--- |
| 5081 |
// dereferenceable bytes in a circular loop now, which will simply |
--- |
5081 |
// dereferenceable bytes in a circular loop now, which will simply |
--- |
| 5082 |
// drive them down to the known value in a very slow way which we |
--- |
5082 |
// drive them down to the known value in a very slow way which we |
--- |
| 5083 |
// can accelerate. |
--- |
5083 |
// can accelerate. |
--- |
| 5084 |
T.indicatePessimisticFixpoint(); |
0 |
5084 |
T.indicatePessimisticFixpoint(); |
0 |
| 5085 |
} |
--- |
5085 |
} |
--- |
| 5086 |
} |
--- |
5086 |
} |
--- |
| 5087 |
|
--- |
5087 |
|
--- |
| 5088 |
return T.isValidState(); |
0 |
5088 |
return T.isValidState(); |
0 |
| 5089 |
}; |
0 |
5089 |
}; |
0 |
| 5090 |
|
--- |
5090 |
|
--- |
| 5091 |
for (const auto &VAC : Values) |
0 |
5091 |
for (const auto &VAC : Values) |
0 |
| 5092 |
if (!VisitValueCB(*VAC.getValue())) |
0 |
5092 |
if (!VisitValueCB(*VAC.getValue())) |
0 |
| 5093 |
return indicatePessimisticFixpoint(); |
0 |
5093 |
return indicatePessimisticFixpoint(); |
0 |
| 5094 |
|
--- |
5094 |
|
--- |
| 5095 |
return clampStateAndIndicateChange(getState(), T); |
0 |
5095 |
return clampStateAndIndicateChange(getState(), T); |
0 |
| 5096 |
} |
0 |
5096 |
} |
0 |
| 5097 |
|
--- |
5097 |
|
--- |
| 5098 |
/// See AbstractAttribute::trackStatistics() |
--- |
5098 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5099 |
void trackStatistics() const override { |
0 |
5099 |
void trackStatistics() const override { |
0 |
| 5100 |
STATS_DECLTRACK_FLOATING_ATTR(dereferenceable) |
0 |
5100 |
STATS_DECLTRACK_FLOATING_ATTR(dereferenceable) |
0 |
| 5101 |
} |
0 |
5101 |
} |
0 |
| 5102 |
}; |
--- |
5102 |
}; |
--- |
| 5103 |
|
--- |
5103 |
|
--- |
| 5104 |
/// Dereferenceable attribute for a return value. |
--- |
5104 |
/// Dereferenceable attribute for a return value. |
--- |
| 5105 |
struct AADereferenceableReturned final |
--- |
5105 |
struct AADereferenceableReturned final |
--- |
| 5106 |
: AAReturnedFromReturnedValues { |
--- |
5106 |
: AAReturnedFromReturnedValues { |
--- |
| 5107 |
using Base = |
--- |
5107 |
using Base = |
--- |
| 5108 |
AAReturnedFromReturnedValues; |
--- |
5108 |
AAReturnedFromReturnedValues; |
--- |
| 5109 |
AADereferenceableReturned(const IRPosition &IRP, Attributor &A) |
0 |
5109 |
AADereferenceableReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 5110 |
: Base(IRP, A) {} |
0 |
5110 |
: Base(IRP, A) {} |
0 |
| 5111 |
|
--- |
5111 |
|
--- |
| 5112 |
/// See AbstractAttribute::trackStatistics() |
--- |
5112 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5113 |
void trackStatistics() const override { |
0 |
5113 |
void trackStatistics() const override { |
0 |
| 5114 |
STATS_DECLTRACK_FNRET_ATTR(dereferenceable) |
0 |
5114 |
STATS_DECLTRACK_FNRET_ATTR(dereferenceable) |
0 |
| 5115 |
} |
0 |
5115 |
} |
0 |
| 5116 |
}; |
--- |
5116 |
}; |
--- |
| 5117 |
|
--- |
5117 |
|
--- |
| 5118 |
/// Dereferenceable attribute for an argument |
--- |
5118 |
/// Dereferenceable attribute for an argument |
--- |
| 5119 |
struct AADereferenceableArgument final |
--- |
5119 |
struct AADereferenceableArgument final |
--- |
| 5120 |
: AAArgumentFromCallSiteArguments
| --- |
5120 |
: AAArgumentFromCallSiteArguments
| --- |
| |
| 5121 |
AADereferenceableImpl> { |
--- |
5121 |
AADereferenceableImpl> { |
--- |
| 5122 |
using Base = |
--- |
5122 |
using Base = |
--- |
| 5123 |
AAArgumentFromCallSiteArguments; |
--- |
5123 |
AAArgumentFromCallSiteArguments; |
--- |
| 5124 |
AADereferenceableArgument(const IRPosition &IRP, Attributor &A) |
0 |
5124 |
AADereferenceableArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 5125 |
: Base(IRP, A) {} |
0 |
5125 |
: Base(IRP, A) {} |
0 |
| 5126 |
|
--- |
5126 |
|
--- |
| 5127 |
/// See AbstractAttribute::trackStatistics() |
--- |
5127 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5128 |
void trackStatistics() const override { |
0 |
5128 |
void trackStatistics() const override { |
0 |
| 5129 |
STATS_DECLTRACK_ARG_ATTR(dereferenceable) |
0 |
5129 |
STATS_DECLTRACK_ARG_ATTR(dereferenceable) |
0 |
| 5130 |
} |
0 |
5130 |
} |
0 |
| 5131 |
}; |
--- |
5131 |
}; |
--- |
| 5132 |
|
--- |
5132 |
|
--- |
| 5133 |
/// Dereferenceable attribute for a call site argument. |
--- |
5133 |
/// Dereferenceable attribute for a call site argument. |
--- |
| 5134 |
struct AADereferenceableCallSiteArgument final : AADereferenceableFloating { |
--- |
5134 |
struct AADereferenceableCallSiteArgument final : AADereferenceableFloating { |
--- |
| 5135 |
AADereferenceableCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
5135 |
AADereferenceableCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 5136 |
: AADereferenceableFloating(IRP, A) {} |
0 |
5136 |
: AADereferenceableFloating(IRP, A) {} |
0 |
| 5137 |
|
--- |
5137 |
|
--- |
| 5138 |
/// See AbstractAttribute::trackStatistics() |
--- |
5138 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5139 |
void trackStatistics() const override { |
0 |
5139 |
void trackStatistics() const override { |
0 |
| 5140 |
STATS_DECLTRACK_CSARG_ATTR(dereferenceable) |
0 |
5140 |
STATS_DECLTRACK_CSARG_ATTR(dereferenceable) |
0 |
| 5141 |
} |
0 |
5141 |
} |
0 |
| 5142 |
}; |
--- |
5142 |
}; |
--- |
| 5143 |
|
--- |
5143 |
|
--- |
| 5144 |
/// Dereferenceable attribute deduction for a call site return value. |
--- |
5144 |
/// Dereferenceable attribute deduction for a call site return value. |
--- |
| 5145 |
struct AADereferenceableCallSiteReturned final |
--- |
5145 |
struct AADereferenceableCallSiteReturned final |
--- |
| 5146 |
: AACallSiteReturnedFromReturned { |
--- |
5146 |
: AACallSiteReturnedFromReturned { |
--- |
| 5147 |
using Base = |
--- |
5147 |
using Base = |
--- |
| 5148 |
AACallSiteReturnedFromReturned; |
--- |
5148 |
AACallSiteReturnedFromReturned; |
--- |
| 5149 |
AADereferenceableCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
5149 |
AADereferenceableCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 5150 |
: Base(IRP, A) {} |
0 |
5150 |
: Base(IRP, A) {} |
0 |
| 5151 |
|
--- |
5151 |
|
--- |
| 5152 |
/// See AbstractAttribute::trackStatistics() |
--- |
5152 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5153 |
void trackStatistics() const override { |
0 |
5153 |
void trackStatistics() const override { |
0 |
| 5154 |
STATS_DECLTRACK_CS_ATTR(dereferenceable); |
0 |
5154 |
STATS_DECLTRACK_CS_ATTR(dereferenceable); |
0 |
| 5155 |
} |
0 |
5155 |
} |
0 |
| 5156 |
}; |
--- |
5156 |
}; |
--- |
| 5157 |
} // namespace |
--- |
5157 |
} // namespace |
--- |
| 5158 |
|
--- |
5158 |
|
--- |
| 5159 |
// ------------------------ Align Argument Attribute ------------------------ |
--- |
5159 |
// ------------------------ Align Argument Attribute ------------------------ |
--- |
| 5160 |
|
--- |
5160 |
|
--- |
| 5161 |
namespace { |
--- |
5161 |
namespace { |
--- |
| 5162 |
static unsigned getKnownAlignForUse(Attributor &A, AAAlign &QueryingAA, |
0 |
5162 |
static unsigned getKnownAlignForUse(Attributor &A, AAAlign &QueryingAA, |
0 |
| 5163 |
Value &AssociatedValue, const Use *U, |
--- |
5163 |
Value &AssociatedValue, const Use *U, |
--- |
| 5164 |
const Instruction *I, bool &TrackUse) { |
--- |
5164 |
const Instruction *I, bool &TrackUse) { |
--- |
| 5165 |
// We need to follow common pointer manipulation uses to the accesses they |
--- |
5165 |
// We need to follow common pointer manipulation uses to the accesses they |
--- |
| 5166 |
// feed into. |
--- |
5166 |
// feed into. |
--- |
| 5167 |
if (isa(I)) { |
0 |
5167 |
if (isa(I)) { |
0 |
| 5168 |
// Follow all but ptr2int casts. |
--- |
5168 |
// Follow all but ptr2int casts. |
--- |
| 5169 |
TrackUse = !isa(I); |
0 |
5169 |
TrackUse = !isa(I); |
0 |
| 5170 |
return 0; |
0 |
5170 |
return 0; |
0 |
| 5171 |
} |
--- |
5171 |
} |
--- |
| 5172 |
if (auto *GEP = dyn_cast(I)) { |
0 |
5172 |
if (auto *GEP = dyn_cast(I)) { |
0 |
| 5173 |
if (GEP->hasAllConstantIndices()) |
0 |
5173 |
if (GEP->hasAllConstantIndices()) |
0 |
| 5174 |
TrackUse = true; |
0 |
5174 |
TrackUse = true; |
0 |
| 5175 |
return 0; |
0 |
5175 |
return 0; |
0 |
| 5176 |
} |
--- |
5176 |
} |
--- |
| 5177 |
|
--- |
5177 |
|
--- |
| 5178 |
MaybeAlign MA; |
0 |
5178 |
MaybeAlign MA; |
0 |
| 5179 |
if (const auto *CB = dyn_cast(I)) { |
0 |
5179 |
if (const auto *CB = dyn_cast(I)) { |
0 |
| 5180 |
if (CB->isBundleOperand(U) || CB->isCallee(U)) |
0 |
5180 |
if (CB->isBundleOperand(U) || CB->isCallee(U)) |
0 |
| 5181 |
return 0; |
0 |
5181 |
return 0; |
0 |
| 5182 |
|
--- |
5182 |
|
--- |
| 5183 |
unsigned ArgNo = CB->getArgOperandNo(U); |
0 |
5183 |
unsigned ArgNo = CB->getArgOperandNo(U); |
0 |
| 5184 |
IRPosition IRP = IRPosition::callsite_argument(*CB, ArgNo); |
0 |
5184 |
IRPosition IRP = IRPosition::callsite_argument(*CB, ArgNo); |
0 |
| 5185 |
// As long as we only use known information there is no need to track |
--- |
5185 |
// As long as we only use known information there is no need to track |
--- |
| 5186 |
// dependences here. |
--- |
5186 |
// dependences here. |
--- |
| 5187 |
auto *AlignAA = A.getAAFor(QueryingAA, IRP, DepClassTy::NONE); |
0 |
5187 |
auto *AlignAA = A.getAAFor(QueryingAA, IRP, DepClassTy::NONE); |
0 |
| 5188 |
if (AlignAA) |
0 |
5188 |
if (AlignAA) |
0 |
| 5189 |
MA = MaybeAlign(AlignAA->getKnownAlign()); |
0 |
5189 |
MA = MaybeAlign(AlignAA->getKnownAlign()); |
0 |
| 5190 |
} |
--- |
5190 |
} |
--- |
| 5191 |
|
--- |
5191 |
|
--- |
| 5192 |
const DataLayout &DL = A.getDataLayout(); |
0 |
5192 |
const DataLayout &DL = A.getDataLayout(); |
0 |
| 5193 |
const Value *UseV = U->get(); |
0 |
5193 |
const Value *UseV = U->get(); |
0 |
| 5194 |
if (auto *SI = dyn_cast(I)) { |
0 |
5194 |
if (auto *SI = dyn_cast(I)) { |
0 |
| 5195 |
if (SI->getPointerOperand() == UseV) |
0 |
5195 |
if (SI->getPointerOperand() == UseV) |
0 |
| 5196 |
MA = SI->getAlign(); |
0 |
5196 |
MA = SI->getAlign(); |
0 |
| 5197 |
} else if (auto *LI = dyn_cast(I)) { |
0 |
5197 |
} else if (auto *LI = dyn_cast(I)) { |
0 |
| 5198 |
if (LI->getPointerOperand() == UseV) |
0 |
5198 |
if (LI->getPointerOperand() == UseV) |
0 |
| 5199 |
MA = LI->getAlign(); |
0 |
5199 |
MA = LI->getAlign(); |
0 |
| 5200 |
} |
--- |
5200 |
} |
--- |
| 5201 |
|
--- |
5201 |
|
--- |
| 5202 |
if (!MA || *MA <= QueryingAA.getKnownAlign()) |
0 |
5202 |
if (!MA || *MA <= QueryingAA.getKnownAlign()) |
0 |
| 5203 |
return 0; |
0 |
5203 |
return 0; |
0 |
| 5204 |
|
--- |
5204 |
|
--- |
| 5205 |
unsigned Alignment = MA->value(); |
0 |
5205 |
unsigned Alignment = MA->value(); |
0 |
| 5206 |
int64_t Offset; |
--- |
5206 |
int64_t Offset; |
--- |
| 5207 |
|
--- |
5207 |
|
--- |
| 5208 |
if (const Value *Base = GetPointerBaseWithConstantOffset(UseV, Offset, DL)) { |
0 |
5208 |
if (const Value *Base = GetPointerBaseWithConstantOffset(UseV, Offset, DL)) { |
0 |
| 5209 |
if (Base == &AssociatedValue) { |
0 |
5209 |
if (Base == &AssociatedValue) { |
0 |
| 5210 |
// BasePointerAddr + Offset = Alignment * Q for some integer Q. |
--- |
5210 |
// BasePointerAddr + Offset = Alignment * Q for some integer Q. |
--- |
| 5211 |
// So we can say that the maximum power of two which is a divisor of |
--- |
5211 |
// So we can say that the maximum power of two which is a divisor of |
--- |
| 5212 |
// gcd(Offset, Alignment) is an alignment. |
--- |
5212 |
// gcd(Offset, Alignment) is an alignment. |
--- |
| 5213 |
|
--- |
5213 |
|
--- |
| 5214 |
uint32_t gcd = std::gcd(uint32_t(abs((int32_t)Offset)), Alignment); |
0 |
5214 |
uint32_t gcd = std::gcd(uint32_t(abs((int32_t)Offset)), Alignment); |
0 |
| 5215 |
Alignment = llvm::bit_floor(gcd); |
0 |
5215 |
Alignment = llvm::bit_floor(gcd); |
0 |
| 5216 |
} |
--- |
5216 |
} |
--- |
| 5217 |
} |
--- |
5217 |
} |
--- |
| 5218 |
|
--- |
5218 |
|
--- |
| 5219 |
return Alignment; |
0 |
5219 |
return Alignment; |
0 |
| 5220 |
} |
--- |
5220 |
} |
--- |
| 5221 |
|
--- |
5221 |
|
--- |
| 5222 |
struct AAAlignImpl : AAAlign { |
--- |
5222 |
struct AAAlignImpl : AAAlign { |
--- |
| 5223 |
AAAlignImpl(const IRPosition &IRP, Attributor &A) : AAAlign(IRP, A) {} |
0 |
5223 |
AAAlignImpl(const IRPosition &IRP, Attributor &A) : AAAlign(IRP, A) {} |
0 |
| 5224 |
|
--- |
5224 |
|
--- |
| 5225 |
/// See AbstractAttribute::initialize(...). |
--- |
5225 |
/// See AbstractAttribute::initialize(...). |
--- |
| 5226 |
void initialize(Attributor &A) override { |
0 |
5226 |
void initialize(Attributor &A) override { |
0 |
| 5227 |
SmallVector Attrs; |
0 |
5227 |
SmallVector Attrs; |
0 |
| 5228 |
A.getAttrs(getIRPosition(), {Attribute::Alignment}, Attrs); |
0 |
5228 |
A.getAttrs(getIRPosition(), {Attribute::Alignment}, Attrs); |
0 |
| 5229 |
for (const Attribute &Attr : Attrs) |
0 |
5229 |
for (const Attribute &Attr : Attrs) |
0 |
| 5230 |
takeKnownMaximum(Attr.getValueAsInt()); |
0 |
5230 |
takeKnownMaximum(Attr.getValueAsInt()); |
0 |
| 5231 |
|
--- |
5231 |
|
--- |
| 5232 |
Value &V = *getAssociatedValue().stripPointerCasts(); |
0 |
5232 |
Value &V = *getAssociatedValue().stripPointerCasts(); |
0 |
| 5233 |
takeKnownMaximum(V.getPointerAlignment(A.getDataLayout()).value()); |
0 |
5233 |
takeKnownMaximum(V.getPointerAlignment(A.getDataLayout()).value()); |
0 |
| 5234 |
|
--- |
5234 |
|
--- |
| 5235 |
if (Instruction *CtxI = getCtxI()) |
0 |
5235 |
if (Instruction *CtxI = getCtxI()) |
0 |
| 5236 |
followUsesInMBEC(*this, A, getState(), *CtxI); |
0 |
5236 |
followUsesInMBEC(*this, A, getState(), *CtxI); |
0 |
| 5237 |
} |
0 |
5237 |
} |
0 |
| 5238 |
|
--- |
5238 |
|
--- |
| 5239 |
/// See AbstractAttribute::manifest(...). |
--- |
5239 |
/// See AbstractAttribute::manifest(...). |
--- |
| 5240 |
ChangeStatus manifest(Attributor &A) override { |
0 |
5240 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 5241 |
ChangeStatus LoadStoreChanged = ChangeStatus::UNCHANGED; |
0 |
5241 |
ChangeStatus LoadStoreChanged = ChangeStatus::UNCHANGED; |
0 |
| 5242 |
|
--- |
5242 |
|
--- |
| 5243 |
// Check for users that allow alignment annotations. |
--- |
5243 |
// Check for users that allow alignment annotations. |
--- |
| 5244 |
Value &AssociatedValue = getAssociatedValue(); |
0 |
5244 |
Value &AssociatedValue = getAssociatedValue(); |
0 |
| 5245 |
for (const Use &U : AssociatedValue.uses()) { |
0 |
5245 |
for (const Use &U : AssociatedValue.uses()) { |
0 |
| 5246 |
if (auto *SI = dyn_cast(U.getUser())) { |
0 |
5246 |
if (auto *SI = dyn_cast(U.getUser())) { |
0 |
| 5247 |
if (SI->getPointerOperand() == &AssociatedValue) |
0 |
5247 |
if (SI->getPointerOperand() == &AssociatedValue) |
0 |
| 5248 |
if (SI->getAlign() < getAssumedAlign()) { |
0 |
5248 |
if (SI->getAlign() < getAssumedAlign()) { |
0 |
| 5249 |
STATS_DECLTRACK(AAAlign, Store, |
0 |
5249 |
STATS_DECLTRACK(AAAlign, Store, |
0 |
| 5250 |
"Number of times alignment added to a store"); |
--- |
5250 |
"Number of times alignment added to a store"); |
--- |
| 5251 |
SI->setAlignment(getAssumedAlign()); |
0 |
5251 |
SI->setAlignment(getAssumedAlign()); |
0 |
| 5252 |
LoadStoreChanged = ChangeStatus::CHANGED; |
0 |
5252 |
LoadStoreChanged = ChangeStatus::CHANGED; |
0 |
| 5253 |
} |
--- |
5253 |
} |
--- |
| 5254 |
} else if (auto *LI = dyn_cast(U.getUser())) { |
0 |
5254 |
} else if (auto *LI = dyn_cast(U.getUser())) { |
0 |
| 5255 |
if (LI->getPointerOperand() == &AssociatedValue) |
0 |
5255 |
if (LI->getPointerOperand() == &AssociatedValue) |
0 |
| 5256 |
if (LI->getAlign() < getAssumedAlign()) { |
0 |
5256 |
if (LI->getAlign() < getAssumedAlign()) { |
0 |
| 5257 |
LI->setAlignment(getAssumedAlign()); |
0 |
5257 |
LI->setAlignment(getAssumedAlign()); |
0 |
| 5258 |
STATS_DECLTRACK(AAAlign, Load, |
0 |
5258 |
STATS_DECLTRACK(AAAlign, Load, |
0 |
| 5259 |
"Number of times alignment added to a load"); |
--- |
5259 |
"Number of times alignment added to a load"); |
--- |
| 5260 |
LoadStoreChanged = ChangeStatus::CHANGED; |
0 |
5260 |
LoadStoreChanged = ChangeStatus::CHANGED; |
0 |
| 5261 |
} |
--- |
5261 |
} |
--- |
| 5262 |
} |
--- |
5262 |
} |
--- |
| 5263 |
} |
--- |
5263 |
} |
--- |
| 5264 |
|
--- |
5264 |
|
--- |
| 5265 |
ChangeStatus Changed = AAAlign::manifest(A); |
0 |
5265 |
ChangeStatus Changed = AAAlign::manifest(A); |
0 |
| 5266 |
|
--- |
5266 |
|
--- |
| 5267 |
Align InheritAlign = |
--- |
5267 |
Align InheritAlign = |
--- |
| 5268 |
getAssociatedValue().getPointerAlignment(A.getDataLayout()); |
0 |
5268 |
getAssociatedValue().getPointerAlignment(A.getDataLayout()); |
0 |
| 5269 |
if (InheritAlign >= getAssumedAlign()) |
0 |
5269 |
if (InheritAlign >= getAssumedAlign()) |
0 |
| 5270 |
return LoadStoreChanged; |
0 |
5270 |
return LoadStoreChanged; |
0 |
| 5271 |
return Changed | LoadStoreChanged; |
0 |
5271 |
return Changed | LoadStoreChanged; |
0 |
| 5272 |
} |
--- |
5272 |
} |
--- |
| 5273 |
|
--- |
5273 |
|
--- |
| 5274 |
// TODO: Provide a helper to determine the implied ABI alignment and check in |
--- |
5274 |
// TODO: Provide a helper to determine the implied ABI alignment and check in |
--- |
| 5275 |
// the existing manifest method and a new one for AAAlignImpl that value |
--- |
5275 |
// the existing manifest method and a new one for AAAlignImpl that value |
--- |
| 5276 |
// to avoid making the alignment explicit if it did not improve. |
--- |
5276 |
// to avoid making the alignment explicit if it did not improve. |
--- |
| 5277 |
|
--- |
5277 |
|
--- |
| 5278 |
/// See AbstractAttribute::getDeducedAttributes |
--- |
5278 |
/// See AbstractAttribute::getDeducedAttributes |
--- |
| 5279 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
5279 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
| 5280 |
SmallVectorImpl &Attrs) const override { |
--- |
5280 |
SmallVectorImpl &Attrs) const override { |
--- |
| 5281 |
if (getAssumedAlign() > 1) |
0 |
5281 |
if (getAssumedAlign() > 1) |
0 |
| 5282 |
Attrs.emplace_back( |
0 |
5282 |
Attrs.emplace_back( |
0 |
| 5283 |
Attribute::getWithAlignment(Ctx, Align(getAssumedAlign()))); |
0 |
5283 |
Attribute::getWithAlignment(Ctx, Align(getAssumedAlign()))); |
0 |
| 5284 |
} |
0 |
5284 |
} |
0 |
| 5285 |
|
--- |
5285 |
|
--- |
| 5286 |
/// See followUsesInMBEC |
--- |
5286 |
/// See followUsesInMBEC |
--- |
| 5287 |
bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I, |
0 |
5287 |
bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I, |
0 |
| 5288 |
AAAlign::StateType &State) { |
--- |
5288 |
AAAlign::StateType &State) { |
--- |
| 5289 |
bool TrackUse = false; |
0 |
5289 |
bool TrackUse = false; |
0 |
| 5290 |
|
--- |
5290 |
|
--- |
| 5291 |
unsigned int KnownAlign = |
--- |
5291 |
unsigned int KnownAlign = |
--- |
| 5292 |
getKnownAlignForUse(A, *this, getAssociatedValue(), U, I, TrackUse); |
0 |
5292 |
getKnownAlignForUse(A, *this, getAssociatedValue(), U, I, TrackUse); |
0 |
| 5293 |
State.takeKnownMaximum(KnownAlign); |
0 |
5293 |
State.takeKnownMaximum(KnownAlign); |
0 |
| 5294 |
|
--- |
5294 |
|
--- |
| 5295 |
return TrackUse; |
0 |
5295 |
return TrackUse; |
0 |
| 5296 |
} |
--- |
5296 |
} |
--- |
| 5297 |
|
--- |
5297 |
|
--- |
| 5298 |
/// See AbstractAttribute::getAsStr(). |
--- |
5298 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 5299 |
const std::string getAsStr(Attributor *A) const override { |
0 |
5299 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 5300 |
return "align<" + std::to_string(getKnownAlign().value()) + "-" + |
0 |
5300 |
return "align<" + std::to_string(getKnownAlign().value()) + "-" + |
0 |
| 5301 |
std::to_string(getAssumedAlign().value()) + ">"; |
0 |
5301 |
std::to_string(getAssumedAlign().value()) + ">"; |
0 |
| 5302 |
} |
--- |
5302 |
} |
--- |
| 5303 |
}; |
--- |
5303 |
}; |
--- |
| 5304 |
|
--- |
5304 |
|
--- |
| 5305 |
/// Align attribute for a floating value. |
--- |
5305 |
/// Align attribute for a floating value. |
--- |
| 5306 |
struct AAAlignFloating : AAAlignImpl { |
--- |
5306 |
struct AAAlignFloating : AAAlignImpl { |
--- |
| 5307 |
AAAlignFloating(const IRPosition &IRP, Attributor &A) : AAAlignImpl(IRP, A) {} |
0 |
5307 |
AAAlignFloating(const IRPosition &IRP, Attributor &A) : AAAlignImpl(IRP, A) {} |
0 |
| 5308 |
|
--- |
5308 |
|
--- |
| 5309 |
/// See AbstractAttribute::updateImpl(...). |
--- |
5309 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 5310 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
5310 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 5311 |
const DataLayout &DL = A.getDataLayout(); |
0 |
5311 |
const DataLayout &DL = A.getDataLayout(); |
0 |
| 5312 |
|
--- |
5312 |
|
--- |
| 5313 |
bool Stripped; |
--- |
5313 |
bool Stripped; |
--- |
| 5314 |
bool UsedAssumedInformation = false; |
0 |
5314 |
bool UsedAssumedInformation = false; |
0 |
| 5315 |
SmallVector Values; |
0 |
5315 |
SmallVector Values; |
0 |
| 5316 |
if (!A.getAssumedSimplifiedValues(getIRPosition(), *this, Values, |
0 |
5316 |
if (!A.getAssumedSimplifiedValues(getIRPosition(), *this, Values, |
0 |
| 5317 |
AA::AnyScope, UsedAssumedInformation)) { |
--- |
5317 |
AA::AnyScope, UsedAssumedInformation)) { |
--- |
| 5318 |
Values.push_back({getAssociatedValue(), getCtxI()}); |
0 |
5318 |
Values.push_back({getAssociatedValue(), getCtxI()}); |
0 |
| 5319 |
Stripped = false; |
0 |
5319 |
Stripped = false; |
0 |
| 5320 |
} else { |
--- |
5320 |
} else { |
--- |
| 5321 |
Stripped = Values.size() != 1 || |
0 |
5321 |
Stripped = Values.size() != 1 || |
0 |
| 5322 |
Values.front().getValue() != &getAssociatedValue(); |
0 |
5322 |
Values.front().getValue() != &getAssociatedValue(); |
0 |
| 5323 |
} |
--- |
5323 |
} |
--- |
| 5324 |
|
--- |
5324 |
|
--- |
| 5325 |
StateType T; |
0 |
5325 |
StateType T; |
0 |
| 5326 |
auto VisitValueCB = [&](Value &V) -> bool { |
0 |
5326 |
auto VisitValueCB = [&](Value &V) -> bool { |
0 |
| 5327 |
if (isa(V) || isa(V)) |
0 |
5327 |
if (isa(V) || isa(V)) |
0 |
| 5328 |
return true; |
0 |
5328 |
return true; |
0 |
| 5329 |
const auto *AA = A.getAAFor(*this, IRPosition::value(V), |
0 |
5329 |
const auto *AA = A.getAAFor(*this, IRPosition::value(V), |
0 |
| 5330 |
DepClassTy::REQUIRED); |
--- |
5330 |
DepClassTy::REQUIRED); |
--- |
| 5331 |
if (!AA || (!Stripped && this == AA)) { |
0 |
5331 |
if (!AA || (!Stripped && this == AA)) { |
0 |
| 5332 |
int64_t Offset; |
--- |
5332 |
int64_t Offset; |
--- |
| 5333 |
unsigned Alignment = 1; |
0 |
5333 |
unsigned Alignment = 1; |
0 |
| 5334 |
if (const Value *Base = |
0 |
5334 |
if (const Value *Base = |
0 |
| 5335 |
GetPointerBaseWithConstantOffset(&V, Offset, DL)) { |
0 |
5335 |
GetPointerBaseWithConstantOffset(&V, Offset, DL)) { |
0 |
| 5336 |
// TODO: Use AAAlign for the base too. |
--- |
5336 |
// TODO: Use AAAlign for the base too. |
--- |
| 5337 |
Align PA = Base->getPointerAlignment(DL); |
0 |
5337 |
Align PA = Base->getPointerAlignment(DL); |
0 |
| 5338 |
// BasePointerAddr + Offset = Alignment * Q for some integer Q. |
--- |
5338 |
// BasePointerAddr + Offset = Alignment * Q for some integer Q. |
--- |
| 5339 |
// So we can say that the maximum power of two which is a divisor of |
--- |
5339 |
// So we can say that the maximum power of two which is a divisor of |
--- |
| 5340 |
// gcd(Offset, Alignment) is an alignment. |
--- |
5340 |
// gcd(Offset, Alignment) is an alignment. |
--- |
| 5341 |
|
--- |
5341 |
|
--- |
| 5342 |
uint32_t gcd = |
--- |
5342 |
uint32_t gcd = |
--- |
| 5343 |
std::gcd(uint32_t(abs((int32_t)Offset)), uint32_t(PA.value())); |
0 |
5343 |
std::gcd(uint32_t(abs((int32_t)Offset)), uint32_t(PA.value())); |
0 |
| 5344 |
Alignment = llvm::bit_floor(gcd); |
0 |
5344 |
Alignment = llvm::bit_floor(gcd); |
0 |
| 5345 |
} else { |
--- |
5345 |
} else { |
--- |
| 5346 |
Alignment = V.getPointerAlignment(DL).value(); |
0 |
5346 |
Alignment = V.getPointerAlignment(DL).value(); |
0 |
| 5347 |
} |
--- |
5347 |
} |
--- |
| 5348 |
// Use only IR information if we did not strip anything. |
--- |
5348 |
// Use only IR information if we did not strip anything. |
--- |
| 5349 |
T.takeKnownMaximum(Alignment); |
0 |
5349 |
T.takeKnownMaximum(Alignment); |
0 |
| 5350 |
T.indicatePessimisticFixpoint(); |
0 |
5350 |
T.indicatePessimisticFixpoint(); |
0 |
| 5351 |
} else { |
0 |
5351 |
} else { |
0 |
| 5352 |
// Use abstract attribute information. |
--- |
5352 |
// Use abstract attribute information. |
--- |
| 5353 |
const AAAlign::StateType &DS = AA->getState(); |
0 |
5353 |
const AAAlign::StateType &DS = AA->getState(); |
0 |
| 5354 |
T ^= DS; |
0 |
5354 |
T ^= DS; |
0 |
| 5355 |
} |
--- |
5355 |
} |
--- |
| 5356 |
return T.isValidState(); |
0 |
5356 |
return T.isValidState(); |
0 |
| 5357 |
}; |
0 |
5357 |
}; |
0 |
| 5358 |
|
--- |
5358 |
|
--- |
| 5359 |
for (const auto &VAC : Values) { |
0 |
5359 |
for (const auto &VAC : Values) { |
0 |
| 5360 |
if (!VisitValueCB(*VAC.getValue())) |
0 |
5360 |
if (!VisitValueCB(*VAC.getValue())) |
0 |
| 5361 |
return indicatePessimisticFixpoint(); |
0 |
5361 |
return indicatePessimisticFixpoint(); |
0 |
| 5362 |
} |
--- |
5362 |
} |
--- |
| 5363 |
|
--- |
5363 |
|
--- |
| 5364 |
// TODO: If we know we visited all incoming values, thus no are assumed |
--- |
5364 |
// TODO: If we know we visited all incoming values, thus no are assumed |
--- |
| 5365 |
// dead, we can take the known information from the state T. |
--- |
5365 |
// dead, we can take the known information from the state T. |
--- |
| 5366 |
return clampStateAndIndicateChange(getState(), T); |
0 |
5366 |
return clampStateAndIndicateChange(getState(), T); |
0 |
| 5367 |
} |
0 |
5367 |
} |
0 |
| 5368 |
|
--- |
5368 |
|
--- |
| 5369 |
/// See AbstractAttribute::trackStatistics() |
--- |
5369 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5370 |
void trackStatistics() const override { STATS_DECLTRACK_FLOATING_ATTR(align) } |
0 |
5370 |
void trackStatistics() const override { STATS_DECLTRACK_FLOATING_ATTR(align) } |
0 |
| 5371 |
}; |
--- |
5371 |
}; |
--- |
| 5372 |
|
--- |
5372 |
|
--- |
| 5373 |
/// Align attribute for function return value. |
--- |
5373 |
/// Align attribute for function return value. |
--- |
| 5374 |
struct AAAlignReturned final |
--- |
5374 |
struct AAAlignReturned final |
--- |
| 5375 |
: AAReturnedFromReturnedValues { |
--- |
5375 |
: AAReturnedFromReturnedValues { |
--- |
| 5376 |
using Base = AAReturnedFromReturnedValues; |
--- |
5376 |
using Base = AAReturnedFromReturnedValues; |
--- |
| 5377 |
AAAlignReturned(const IRPosition &IRP, Attributor &A) : Base(IRP, A) {} |
0 |
5377 |
AAAlignReturned(const IRPosition &IRP, Attributor &A) : Base(IRP, A) {} |
0 |
| 5378 |
|
--- |
5378 |
|
--- |
| 5379 |
/// See AbstractAttribute::trackStatistics() |
--- |
5379 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5380 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(aligned) } |
0 |
5380 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(aligned) } |
0 |
| 5381 |
}; |
--- |
5381 |
}; |
--- |
| 5382 |
|
--- |
5382 |
|
--- |
| 5383 |
/// Align attribute for function argument. |
--- |
5383 |
/// Align attribute for function argument. |
--- |
| 5384 |
struct AAAlignArgument final |
--- |
5384 |
struct AAAlignArgument final |
--- |
| 5385 |
: AAArgumentFromCallSiteArguments { |
--- |
5385 |
: AAArgumentFromCallSiteArguments { |
--- |
| 5386 |
using Base = AAArgumentFromCallSiteArguments; |
--- |
5386 |
using Base = AAArgumentFromCallSiteArguments; |
--- |
| 5387 |
AAAlignArgument(const IRPosition &IRP, Attributor &A) : Base(IRP, A) {} |
0 |
5387 |
AAAlignArgument(const IRPosition &IRP, Attributor &A) : Base(IRP, A) {} |
0 |
| 5388 |
|
--- |
5388 |
|
--- |
| 5389 |
/// See AbstractAttribute::manifest(...). |
--- |
5389 |
/// See AbstractAttribute::manifest(...). |
--- |
| 5390 |
ChangeStatus manifest(Attributor &A) override { |
0 |
5390 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 5391 |
// If the associated argument is involved in a must-tail call we give up |
--- |
5391 |
// If the associated argument is involved in a must-tail call we give up |
--- |
| 5392 |
// because we would need to keep the argument alignments of caller and |
--- |
5392 |
// because we would need to keep the argument alignments of caller and |
--- |
| 5393 |
// callee in-sync. Just does not seem worth the trouble right now. |
--- |
5393 |
// callee in-sync. Just does not seem worth the trouble right now. |
--- |
| 5394 |
if (A.getInfoCache().isInvolvedInMustTailCall(*getAssociatedArgument())) |
0 |
5394 |
if (A.getInfoCache().isInvolvedInMustTailCall(*getAssociatedArgument())) |
0 |
| 5395 |
return ChangeStatus::UNCHANGED; |
0 |
5395 |
return ChangeStatus::UNCHANGED; |
0 |
| 5396 |
return Base::manifest(A); |
0 |
5396 |
return Base::manifest(A); |
0 |
| 5397 |
} |
--- |
5397 |
} |
--- |
| 5398 |
|
--- |
5398 |
|
--- |
| 5399 |
/// See AbstractAttribute::trackStatistics() |
--- |
5399 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5400 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(aligned) } |
0 |
5400 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(aligned) } |
0 |
| 5401 |
}; |
--- |
5401 |
}; |
--- |
| 5402 |
|
--- |
5402 |
|
--- |
| 5403 |
struct AAAlignCallSiteArgument final : AAAlignFloating { |
--- |
5403 |
struct AAAlignCallSiteArgument final : AAAlignFloating { |
--- |
| 5404 |
AAAlignCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
5404 |
AAAlignCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 5405 |
: AAAlignFloating(IRP, A) {} |
0 |
5405 |
: AAAlignFloating(IRP, A) {} |
0 |
| 5406 |
|
--- |
5406 |
|
--- |
| 5407 |
/// See AbstractAttribute::manifest(...). |
--- |
5407 |
/// See AbstractAttribute::manifest(...). |
--- |
| 5408 |
ChangeStatus manifest(Attributor &A) override { |
0 |
5408 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 5409 |
// If the associated argument is involved in a must-tail call we give up |
--- |
5409 |
// If the associated argument is involved in a must-tail call we give up |
--- |
| 5410 |
// because we would need to keep the argument alignments of caller and |
--- |
5410 |
// because we would need to keep the argument alignments of caller and |
--- |
| 5411 |
// callee in-sync. Just does not seem worth the trouble right now. |
--- |
5411 |
// callee in-sync. Just does not seem worth the trouble right now. |
--- |
| 5412 |
if (Argument *Arg = getAssociatedArgument()) |
0 |
5412 |
if (Argument *Arg = getAssociatedArgument()) |
0 |
| 5413 |
if (A.getInfoCache().isInvolvedInMustTailCall(*Arg)) |
0 |
5413 |
if (A.getInfoCache().isInvolvedInMustTailCall(*Arg)) |
0 |
| 5414 |
return ChangeStatus::UNCHANGED; |
0 |
5414 |
return ChangeStatus::UNCHANGED; |
0 |
| 5415 |
ChangeStatus Changed = AAAlignImpl::manifest(A); |
0 |
5415 |
ChangeStatus Changed = AAAlignImpl::manifest(A); |
0 |
| 5416 |
Align InheritAlign = |
--- |
5416 |
Align InheritAlign = |
--- |
| 5417 |
getAssociatedValue().getPointerAlignment(A.getDataLayout()); |
0 |
5417 |
getAssociatedValue().getPointerAlignment(A.getDataLayout()); |
0 |
| 5418 |
if (InheritAlign >= getAssumedAlign()) |
0 |
5418 |
if (InheritAlign >= getAssumedAlign()) |
0 |
| 5419 |
Changed = ChangeStatus::UNCHANGED; |
0 |
5419 |
Changed = ChangeStatus::UNCHANGED; |
0 |
| 5420 |
return Changed; |
0 |
5420 |
return Changed; |
0 |
| 5421 |
} |
--- |
5421 |
} |
--- |
| 5422 |
|
--- |
5422 |
|
--- |
| 5423 |
/// See AbstractAttribute::updateImpl(Attributor &A). |
--- |
5423 |
/// See AbstractAttribute::updateImpl(Attributor &A). |
--- |
| 5424 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
5424 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 5425 |
ChangeStatus Changed = AAAlignFloating::updateImpl(A); |
0 |
5425 |
ChangeStatus Changed = AAAlignFloating::updateImpl(A); |
0 |
| 5426 |
if (Argument *Arg = getAssociatedArgument()) { |
0 |
5426 |
if (Argument *Arg = getAssociatedArgument()) { |
0 |
| 5427 |
// We only take known information from the argument |
--- |
5427 |
// We only take known information from the argument |
--- |
| 5428 |
// so we do not need to track a dependence. |
--- |
5428 |
// so we do not need to track a dependence. |
--- |
| 5429 |
const auto *ArgAlignAA = A.getAAFor( |
0 |
5429 |
const auto *ArgAlignAA = A.getAAFor( |
0 |
| 5430 |
*this, IRPosition::argument(*Arg), DepClassTy::NONE); |
0 |
5430 |
*this, IRPosition::argument(*Arg), DepClassTy::NONE); |
0 |
| 5431 |
if (ArgAlignAA) |
0 |
5431 |
if (ArgAlignAA) |
0 |
| 5432 |
takeKnownMaximum(ArgAlignAA->getKnownAlign().value()); |
0 |
5432 |
takeKnownMaximum(ArgAlignAA->getKnownAlign().value()); |
0 |
| 5433 |
} |
--- |
5433 |
} |
--- |
| 5434 |
return Changed; |
0 |
5434 |
return Changed; |
0 |
| 5435 |
} |
--- |
5435 |
} |
--- |
| 5436 |
|
--- |
5436 |
|
--- |
| 5437 |
/// See AbstractAttribute::trackStatistics() |
--- |
5437 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5438 |
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(aligned) } |
0 |
5438 |
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(aligned) } |
0 |
| 5439 |
}; |
--- |
5439 |
}; |
--- |
| 5440 |
|
--- |
5440 |
|
--- |
| 5441 |
/// Align attribute deduction for a call site return value. |
--- |
5441 |
/// Align attribute deduction for a call site return value. |
--- |
| 5442 |
struct AAAlignCallSiteReturned final |
--- |
5442 |
struct AAAlignCallSiteReturned final |
--- |
| 5443 |
: AACallSiteReturnedFromReturned { |
--- |
5443 |
: AACallSiteReturnedFromReturned { |
--- |
| 5444 |
using Base = AACallSiteReturnedFromReturned; |
--- |
5444 |
using Base = AACallSiteReturnedFromReturned; |
--- |
| 5445 |
AAAlignCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
5445 |
AAAlignCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 5446 |
: Base(IRP, A) {} |
0 |
5446 |
: Base(IRP, A) {} |
0 |
| 5447 |
|
--- |
5447 |
|
--- |
| 5448 |
/// See AbstractAttribute::trackStatistics() |
--- |
5448 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5449 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(align); } |
0 |
5449 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(align); } |
0 |
| 5450 |
}; |
--- |
5450 |
}; |
--- |
| 5451 |
} // namespace |
--- |
5451 |
} // namespace |
--- |
| 5452 |
|
--- |
5452 |
|
--- |
| 5453 |
/// ------------------ Function No-Return Attribute ---------------------------- |
--- |
5453 |
/// ------------------ Function No-Return Attribute ---------------------------- |
--- |
| 5454 |
namespace { |
--- |
5454 |
namespace { |
--- |
| 5455 |
struct AANoReturnImpl : public AANoReturn { |
--- |
5455 |
struct AANoReturnImpl : public AANoReturn { |
--- |
| 5456 |
AANoReturnImpl(const IRPosition &IRP, Attributor &A) : AANoReturn(IRP, A) {} |
0 |
5456 |
AANoReturnImpl(const IRPosition &IRP, Attributor &A) : AANoReturn(IRP, A) {} |
0 |
| 5457 |
|
--- |
5457 |
|
--- |
| 5458 |
/// See AbstractAttribute::initialize(...). |
--- |
5458 |
/// See AbstractAttribute::initialize(...). |
--- |
| 5459 |
void initialize(Attributor &A) override { |
0 |
5459 |
void initialize(Attributor &A) override { |
0 |
| 5460 |
bool IsKnown; |
--- |
5460 |
bool IsKnown; |
--- |
| 5461 |
assert(!AA::hasAssumedIRAttr( |
0 |
5461 |
assert(!AA::hasAssumedIRAttr( |
0 |
| 5462 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
5462 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
| 5463 |
(void)IsKnown; |
--- |
5463 |
(void)IsKnown; |
--- |
| 5464 |
} |
0 |
5464 |
} |
0 |
| 5465 |
|
--- |
5465 |
|
--- |
| 5466 |
/// See AbstractAttribute::getAsStr(). |
--- |
5466 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 5467 |
const std::string getAsStr(Attributor *A) const override { |
0 |
5467 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 5468 |
return getAssumed() ? "noreturn" : "may-return"; |
0 |
5468 |
return getAssumed() ? "noreturn" : "may-return"; |
0 |
| 5469 |
} |
--- |
5469 |
} |
--- |
| 5470 |
|
--- |
5470 |
|
--- |
| 5471 |
/// See AbstractAttribute::updateImpl(Attributor &A). |
--- |
5471 |
/// See AbstractAttribute::updateImpl(Attributor &A). |
--- |
| 5472 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
5472 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 5473 |
auto CheckForNoReturn = [](Instruction &) { return false; }; |
0 |
5473 |
auto CheckForNoReturn = [](Instruction &) { return false; }; |
0 |
| 5474 |
bool UsedAssumedInformation = false; |
0 |
5474 |
bool UsedAssumedInformation = false; |
0 |
| 5475 |
if (!A.checkForAllInstructions(CheckForNoReturn, *this, |
0 |
5475 |
if (!A.checkForAllInstructions(CheckForNoReturn, *this, |
0 |
| 5476 |
{(unsigned)Instruction::Ret}, |
--- |
5476 |
{(unsigned)Instruction::Ret}, |
--- |
| 5477 |
UsedAssumedInformation)) |
--- |
5477 |
UsedAssumedInformation)) |
--- |
| 5478 |
return indicatePessimisticFixpoint(); |
0 |
5478 |
return indicatePessimisticFixpoint(); |
0 |
| 5479 |
return ChangeStatus::UNCHANGED; |
0 |
5479 |
return ChangeStatus::UNCHANGED; |
0 |
| 5480 |
} |
--- |
5480 |
} |
--- |
| 5481 |
}; |
--- |
5481 |
}; |
--- |
| 5482 |
|
--- |
5482 |
|
--- |
| 5483 |
struct AANoReturnFunction final : AANoReturnImpl { |
--- |
5483 |
struct AANoReturnFunction final : AANoReturnImpl { |
--- |
| 5484 |
AANoReturnFunction(const IRPosition &IRP, Attributor &A) |
0 |
5484 |
AANoReturnFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 5485 |
: AANoReturnImpl(IRP, A) {} |
0 |
5485 |
: AANoReturnImpl(IRP, A) {} |
0 |
| 5486 |
|
--- |
5486 |
|
--- |
| 5487 |
/// See AbstractAttribute::trackStatistics() |
--- |
5487 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5488 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(noreturn) } |
0 |
5488 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(noreturn) } |
0 |
| 5489 |
}; |
--- |
5489 |
}; |
--- |
| 5490 |
|
--- |
5490 |
|
--- |
| 5491 |
/// NoReturn attribute deduction for a call sites. |
--- |
5491 |
/// NoReturn attribute deduction for a call sites. |
--- |
| 5492 |
struct AANoReturnCallSite final : AANoReturnImpl { |
--- |
5492 |
struct AANoReturnCallSite final : AANoReturnImpl { |
--- |
| 5493 |
AANoReturnCallSite(const IRPosition &IRP, Attributor &A) |
0 |
5493 |
AANoReturnCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 5494 |
: AANoReturnImpl(IRP, A) {} |
0 |
5494 |
: AANoReturnImpl(IRP, A) {} |
0 |
| 5495 |
|
--- |
5495 |
|
--- |
| 5496 |
/// See AbstractAttribute::updateImpl(...). |
--- |
5496 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 5497 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
5497 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 5498 |
// TODO: Once we have call site specific value information we can provide |
--- |
5498 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 5499 |
// call site specific liveness information and then it makes |
--- |
5499 |
// call site specific liveness information and then it makes |
--- |
| 5500 |
// sense to specialize attributes for call sites arguments instead of |
--- |
5500 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 5501 |
// redirecting requests to the callee argument. |
--- |
5501 |
// redirecting requests to the callee argument. |
--- |
| 5502 |
Function *F = getAssociatedFunction(); |
0 |
5502 |
Function *F = getAssociatedFunction(); |
0 |
| 5503 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
5503 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
| 5504 |
bool IsKnownNoReturn; |
--- |
5504 |
bool IsKnownNoReturn; |
--- |
| 5505 |
if (!AA::hasAssumedIRAttr( |
0 |
5505 |
if (!AA::hasAssumedIRAttr( |
0 |
| 5506 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownNoReturn)) |
--- |
5506 |
A, this, FnPos, DepClassTy::REQUIRED, IsKnownNoReturn)) |
--- |
| 5507 |
return indicatePessimisticFixpoint(); |
0 |
5507 |
return indicatePessimisticFixpoint(); |
0 |
| 5508 |
return ChangeStatus::UNCHANGED; |
0 |
5508 |
return ChangeStatus::UNCHANGED; |
0 |
| 5509 |
} |
--- |
5509 |
} |
--- |
| 5510 |
|
--- |
5510 |
|
--- |
| 5511 |
/// See AbstractAttribute::trackStatistics() |
--- |
5511 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5512 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(noreturn); } |
0 |
5512 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(noreturn); } |
0 |
| 5513 |
}; |
--- |
5513 |
}; |
--- |
| 5514 |
} // namespace |
--- |
5514 |
} // namespace |
--- |
| 5515 |
|
--- |
5515 |
|
--- |
| 5516 |
/// ----------------------- Instance Info --------------------------------- |
--- |
5516 |
/// ----------------------- Instance Info --------------------------------- |
--- |
| 5517 |
|
--- |
5517 |
|
--- |
| 5518 |
namespace { |
--- |
5518 |
namespace { |
--- |
| 5519 |
/// A class to hold the state of for no-capture attributes. |
--- |
5519 |
/// A class to hold the state of for no-capture attributes. |
--- |
| 5520 |
struct AAInstanceInfoImpl : public AAInstanceInfo { |
--- |
5520 |
struct AAInstanceInfoImpl : public AAInstanceInfo { |
--- |
| 5521 |
AAInstanceInfoImpl(const IRPosition &IRP, Attributor &A) |
0 |
5521 |
AAInstanceInfoImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 5522 |
: AAInstanceInfo(IRP, A) {} |
0 |
5522 |
: AAInstanceInfo(IRP, A) {} |
0 |
| 5523 |
|
--- |
5523 |
|
--- |
| 5524 |
/// See AbstractAttribute::initialize(...). |
--- |
5524 |
/// See AbstractAttribute::initialize(...). |
--- |
| 5525 |
void initialize(Attributor &A) override { |
0 |
5525 |
void initialize(Attributor &A) override { |
0 |
| 5526 |
Value &V = getAssociatedValue(); |
0 |
5526 |
Value &V = getAssociatedValue(); |
0 |
| 5527 |
if (auto *C = dyn_cast(&V)) { |
0 |
5527 |
if (auto *C = dyn_cast(&V)) { |
0 |
| 5528 |
if (C->isThreadDependent()) |
0 |
5528 |
if (C->isThreadDependent()) |
0 |
| 5529 |
indicatePessimisticFixpoint(); |
0 |
5529 |
indicatePessimisticFixpoint(); |
0 |
| 5530 |
else |
--- |
5530 |
else |
--- |
| 5531 |
indicateOptimisticFixpoint(); |
0 |
5531 |
indicateOptimisticFixpoint(); |
0 |
| 5532 |
return; |
0 |
5532 |
return; |
0 |
| 5533 |
} |
--- |
5533 |
} |
--- |
| 5534 |
if (auto *CB = dyn_cast(&V)) |
0 |
5534 |
if (auto *CB = dyn_cast(&V)) |
0 |
| 5535 |
if (CB->arg_size() == 0 && !CB->mayHaveSideEffects() && |
0 |
5535 |
if (CB->arg_size() == 0 && !CB->mayHaveSideEffects() && |
0 |
| 5536 |
!CB->mayReadFromMemory()) { |
0 |
5536 |
!CB->mayReadFromMemory()) { |
0 |
| 5537 |
indicateOptimisticFixpoint(); |
0 |
5537 |
indicateOptimisticFixpoint(); |
0 |
| 5538 |
return; |
0 |
5538 |
return; |
0 |
| 5539 |
} |
--- |
5539 |
} |
--- |
| 5540 |
if (auto *I = dyn_cast(&V)) { |
0 |
5540 |
if (auto *I = dyn_cast(&V)) { |
0 |
| 5541 |
const auto *CI = |
--- |
5541 |
const auto *CI = |
--- |
| 5542 |
A.getInfoCache().getAnalysisResultForFunction( |
0 |
5542 |
A.getInfoCache().getAnalysisResultForFunction( |
0 |
| 5543 |
*I->getFunction()); |
0 |
5543 |
*I->getFunction()); |
0 |
| 5544 |
if (mayBeInCycle(CI, I, /* HeaderOnly */ false)) { |
0 |
5544 |
if (mayBeInCycle(CI, I, /* HeaderOnly */ false)) { |
0 |
| 5545 |
indicatePessimisticFixpoint(); |
0 |
5545 |
indicatePessimisticFixpoint(); |
0 |
| 5546 |
return; |
0 |
5546 |
return; |
0 |
| 5547 |
} |
--- |
5547 |
} |
--- |
| 5548 |
} |
--- |
5548 |
} |
--- |
| 5549 |
} |
--- |
5549 |
} |
--- |
| 5550 |
|
--- |
5550 |
|
--- |
| 5551 |
/// See AbstractAttribute::updateImpl(...). |
--- |
5551 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 5552 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
5552 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 5553 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
5553 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 5554 |
|
--- |
5554 |
|
--- |
| 5555 |
Value &V = getAssociatedValue(); |
0 |
5555 |
Value &V = getAssociatedValue(); |
0 |
| 5556 |
const Function *Scope = nullptr; |
0 |
5556 |
const Function *Scope = nullptr; |
0 |
| 5557 |
if (auto *I = dyn_cast(&V)) |
0 |
5557 |
if (auto *I = dyn_cast(&V)) |
0 |
| 5558 |
Scope = I->getFunction(); |
0 |
5558 |
Scope = I->getFunction(); |
0 |
| 5559 |
if (auto *A = dyn_cast(&V)) { |
0 |
5559 |
if (auto *A = dyn_cast(&V)) { |
0 |
| 5560 |
Scope = A->getParent(); |
0 |
5560 |
Scope = A->getParent(); |
0 |
| 5561 |
if (!Scope->hasLocalLinkage()) |
0 |
5561 |
if (!Scope->hasLocalLinkage()) |
0 |
| 5562 |
return Changed; |
0 |
5562 |
return Changed; |
0 |
| 5563 |
} |
--- |
5563 |
} |
--- |
| 5564 |
if (!Scope) |
0 |
5564 |
if (!Scope) |
0 |
| 5565 |
return indicateOptimisticFixpoint(); |
0 |
5565 |
return indicateOptimisticFixpoint(); |
0 |
| 5566 |
|
--- |
5566 |
|
--- |
| 5567 |
bool IsKnownNoRecurse; |
--- |
5567 |
bool IsKnownNoRecurse; |
--- |
| 5568 |
if (AA::hasAssumedIRAttr( |
0 |
5568 |
if (AA::hasAssumedIRAttr( |
0 |
| 5569 |
A, this, IRPosition::function(*Scope), DepClassTy::OPTIONAL, |
0 |
5569 |
A, this, IRPosition::function(*Scope), DepClassTy::OPTIONAL, |
0 |
| 5570 |
IsKnownNoRecurse)) |
--- |
5570 |
IsKnownNoRecurse)) |
--- |
| 5571 |
return Changed; |
0 |
5571 |
return Changed; |
0 |
| 5572 |
|
--- |
5572 |
|
--- |
| 5573 |
auto UsePred = [&](const Use &U, bool &Follow) { |
0 |
5573 |
auto UsePred = [&](const Use &U, bool &Follow) { |
0 |
| 5574 |
const Instruction *UserI = dyn_cast(U.getUser()); |
0 |
5574 |
const Instruction *UserI = dyn_cast(U.getUser()); |
0 |
| 5575 |
if (!UserI || isa(UserI) || isa(UserI) || |
0 |
5575 |
if (!UserI || isa(UserI) || isa(UserI) || |
0 |
| 5576 |
isa(UserI) || isa(UserI)) { |
0 |
5576 |
isa(UserI) || isa(UserI)) { |
0 |
| 5577 |
Follow = true; |
0 |
5577 |
Follow = true; |
0 |
| 5578 |
return true; |
0 |
5578 |
return true; |
0 |
| 5579 |
} |
--- |
5579 |
} |
--- |
| 5580 |
if (isa(UserI) || isa(UserI) || |
0 |
5580 |
if (isa(UserI) || isa(UserI) || |
0 |
| 5581 |
(isa(UserI) && |
0 |
5581 |
(isa(UserI) && |
0 |
| 5582 |
cast(UserI)->getValueOperand() != U.get())) |
0 |
5582 |
cast(UserI)->getValueOperand() != U.get())) |
0 |
| 5583 |
return true; |
0 |
5583 |
return true; |
0 |
| 5584 |
if (auto *CB = dyn_cast(UserI)) { |
0 |
5584 |
if (auto *CB = dyn_cast(UserI)) { |
0 |
| 5585 |
// This check is not guaranteeing uniqueness but for now that we cannot |
--- |
5585 |
// This check is not guaranteeing uniqueness but for now that we cannot |
--- |
| 5586 |
// end up with two versions of \p U thinking it was one. |
--- |
5586 |
// end up with two versions of \p U thinking it was one. |
--- |
| 5587 |
auto *Callee = dyn_cast_if_present(CB->getCalledOperand()); |
0 |
5587 |
auto *Callee = dyn_cast_if_present(CB->getCalledOperand()); |
0 |
| 5588 |
if (!Callee || !Callee->hasLocalLinkage()) |
0 |
5588 |
if (!Callee || !Callee->hasLocalLinkage()) |
0 |
| 5589 |
return true; |
0 |
5589 |
return true; |
0 |
| 5590 |
if (!CB->isArgOperand(&U)) |
0 |
5590 |
if (!CB->isArgOperand(&U)) |
0 |
| 5591 |
return false; |
0 |
5591 |
return false; |
0 |
| 5592 |
const auto *ArgInstanceInfoAA = A.getAAFor( |
0 |
5592 |
const auto *ArgInstanceInfoAA = A.getAAFor( |
0 |
| 5593 |
*this, IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U)), |
0 |
5593 |
*this, IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U)), |
0 |
| 5594 |
DepClassTy::OPTIONAL); |
--- |
5594 |
DepClassTy::OPTIONAL); |
--- |
| 5595 |
if (!ArgInstanceInfoAA || |
0 |
5595 |
if (!ArgInstanceInfoAA || |
0 |
| 5596 |
!ArgInstanceInfoAA->isAssumedUniqueForAnalysis()) |
0 |
5596 |
!ArgInstanceInfoAA->isAssumedUniqueForAnalysis()) |
0 |
| 5597 |
return false; |
0 |
5597 |
return false; |
0 |
| 5598 |
// If this call base might reach the scope again we might forward the |
--- |
5598 |
// If this call base might reach the scope again we might forward the |
--- |
| 5599 |
// argument back here. This is very conservative. |
--- |
5599 |
// argument back here. This is very conservative. |
--- |
| 5600 |
if (AA::isPotentiallyReachable( |
0 |
5600 |
if (AA::isPotentiallyReachable( |
0 |
| 5601 |
A, *CB, *Scope, *this, /* ExclusionSet */ nullptr, |
0 |
5601 |
A, *CB, *Scope, *this, /* ExclusionSet */ nullptr, |
0 |
| 5602 |
[Scope](const Function &Fn) { return &Fn != Scope; })) |
0 |
5602 |
[Scope](const Function &Fn) { return &Fn != Scope; })) |
0 |
| 5603 |
return false; |
0 |
5603 |
return false; |
0 |
| 5604 |
return true; |
0 |
5604 |
return true; |
0 |
| 5605 |
} |
--- |
5605 |
} |
--- |
| 5606 |
return false; |
0 |
5606 |
return false; |
0 |
| 5607 |
}; |
0 |
5607 |
}; |
0 |
| 5608 |
|
--- |
5608 |
|
--- |
| 5609 |
auto EquivalentUseCB = [&](const Use &OldU, const Use &NewU) { |
0 |
5609 |
auto EquivalentUseCB = [&](const Use &OldU, const Use &NewU) { |
0 |
| 5610 |
if (auto *SI = dyn_cast(OldU.getUser())) { |
0 |
5610 |
if (auto *SI = dyn_cast(OldU.getUser())) { |
0 |
| 5611 |
auto *Ptr = SI->getPointerOperand()->stripPointerCasts(); |
0 |
5611 |
auto *Ptr = SI->getPointerOperand()->stripPointerCasts(); |
0 |
| 5612 |
if ((isa(Ptr) || isNoAliasCall(Ptr)) && |
0 |
5612 |
if ((isa(Ptr) || isNoAliasCall(Ptr)) && |
0 |
| 5613 |
AA::isDynamicallyUnique(A, *this, *Ptr)) |
0 |
5613 |
AA::isDynamicallyUnique(A, *this, *Ptr)) |
0 |
| 5614 |
return true; |
0 |
5614 |
return true; |
0 |
| 5615 |
} |
--- |
5615 |
} |
--- |
| 5616 |
return false; |
0 |
5616 |
return false; |
0 |
| 5617 |
}; |
0 |
5617 |
}; |
0 |
| 5618 |
|
--- |
5618 |
|
--- |
| 5619 |
if (!A.checkForAllUses(UsePred, *this, V, /* CheckBBLivenessOnly */ true, |
0 |
5619 |
if (!A.checkForAllUses(UsePred, *this, V, /* CheckBBLivenessOnly */ true, |
0 |
| 5620 |
DepClassTy::OPTIONAL, |
--- |
5620 |
DepClassTy::OPTIONAL, |
--- |
| 5621 |
/* IgnoreDroppableUses */ true, EquivalentUseCB)) |
--- |
5621 |
/* IgnoreDroppableUses */ true, EquivalentUseCB)) |
--- |
| 5622 |
return indicatePessimisticFixpoint(); |
0 |
5622 |
return indicatePessimisticFixpoint(); |
0 |
| 5623 |
|
--- |
5623 |
|
--- |
| 5624 |
return Changed; |
0 |
5624 |
return Changed; |
0 |
| 5625 |
} |
--- |
5625 |
} |
--- |
| 5626 |
|
--- |
5626 |
|
--- |
| 5627 |
/// See AbstractState::getAsStr(). |
--- |
5627 |
/// See AbstractState::getAsStr(). |
--- |
| 5628 |
const std::string getAsStr(Attributor *A) const override { |
0 |
5628 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 5629 |
return isAssumedUniqueForAnalysis() ? "" : ""; |
0 |
5629 |
return isAssumedUniqueForAnalysis() ? "" : ""; |
0 |
| 5630 |
} |
--- |
5630 |
} |
--- |
| 5631 |
|
--- |
5631 |
|
--- |
| 5632 |
/// See AbstractAttribute::trackStatistics() |
--- |
5632 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 5633 |
void trackStatistics() const override {} |
0 |
5633 |
void trackStatistics() const override {} |
0 |
| 5634 |
}; |
--- |
5634 |
}; |
--- |
| 5635 |
|
--- |
5635 |
|
--- |
| 5636 |
/// InstanceInfo attribute for floating values. |
--- |
5636 |
/// InstanceInfo attribute for floating values. |
--- |
| 5637 |
struct AAInstanceInfoFloating : AAInstanceInfoImpl { |
--- |
5637 |
struct AAInstanceInfoFloating : AAInstanceInfoImpl { |
--- |
| 5638 |
AAInstanceInfoFloating(const IRPosition &IRP, Attributor &A) |
0 |
5638 |
AAInstanceInfoFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 5639 |
: AAInstanceInfoImpl(IRP, A) {} |
0 |
5639 |
: AAInstanceInfoImpl(IRP, A) {} |
0 |
| 5640 |
}; |
--- |
5640 |
}; |
--- |
| 5641 |
|
--- |
5641 |
|
--- |
| 5642 |
/// NoCapture attribute for function arguments. |
--- |
5642 |
/// NoCapture attribute for function arguments. |
--- |
| 5643 |
struct AAInstanceInfoArgument final : AAInstanceInfoFloating { |
--- |
5643 |
struct AAInstanceInfoArgument final : AAInstanceInfoFloating { |
--- |
| 5644 |
AAInstanceInfoArgument(const IRPosition &IRP, Attributor &A) |
0 |
5644 |
AAInstanceInfoArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 5645 |
: AAInstanceInfoFloating(IRP, A) {} |
0 |
5645 |
: AAInstanceInfoFloating(IRP, A) {} |
0 |
| 5646 |
}; |
--- |
5646 |
}; |
--- |
| 5647 |
|
--- |
5647 |
|
--- |
| 5648 |
/// InstanceInfo attribute for call site arguments. |
--- |
5648 |
/// InstanceInfo attribute for call site arguments. |
--- |
| 5649 |
struct AAInstanceInfoCallSiteArgument final : AAInstanceInfoImpl { |
--- |
5649 |
struct AAInstanceInfoCallSiteArgument final : AAInstanceInfoImpl { |
--- |
| 5650 |
AAInstanceInfoCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
5650 |
AAInstanceInfoCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 5651 |
: AAInstanceInfoImpl(IRP, A) {} |
0 |
5651 |
: AAInstanceInfoImpl(IRP, A) {} |
0 |
| 5652 |
|
--- |
5652 |
|
--- |
| 5653 |
/// See AbstractAttribute::updateImpl(...). |
--- |
5653 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 5654 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
5654 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 5655 |
// TODO: Once we have call site specific value information we can provide |
--- |
5655 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 5656 |
// call site specific liveness information and then it makes |
--- |
5656 |
// call site specific liveness information and then it makes |
--- |
| 5657 |
// sense to specialize attributes for call sites arguments instead of |
--- |
5657 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 5658 |
// redirecting requests to the callee argument. |
--- |
5658 |
// redirecting requests to the callee argument. |
--- |
| 5659 |
Argument *Arg = getAssociatedArgument(); |
0 |
5659 |
Argument *Arg = getAssociatedArgument(); |
0 |
| 5660 |
if (!Arg) |
0 |
5660 |
if (!Arg) |
0 |
| 5661 |
return indicatePessimisticFixpoint(); |
0 |
5661 |
return indicatePessimisticFixpoint(); |
0 |
| 5662 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
5662 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
| 5663 |
auto *ArgAA = |
--- |
5663 |
auto *ArgAA = |
--- |
| 5664 |
A.getAAFor(*this, ArgPos, DepClassTy::REQUIRED); |
0 |
5664 |
A.getAAFor(*this, ArgPos, DepClassTy::REQUIRED); |
0 |
| 5665 |
if (!ArgAA) |
0 |
5665 |
if (!ArgAA) |
0 |
| 5666 |
return indicatePessimisticFixpoint(); |
0 |
5666 |
return indicatePessimisticFixpoint(); |
0 |
| 5667 |
return clampStateAndIndicateChange(getState(), ArgAA->getState()); |
0 |
5667 |
return clampStateAndIndicateChange(getState(), ArgAA->getState()); |
0 |
| 5668 |
} |
--- |
5668 |
} |
--- |
| 5669 |
}; |
--- |
5669 |
}; |
--- |
| 5670 |
|
--- |
5670 |
|
--- |
| 5671 |
/// InstanceInfo attribute for function return value. |
--- |
5671 |
/// InstanceInfo attribute for function return value. |
--- |
| 5672 |
struct AAInstanceInfoReturned final : AAInstanceInfoImpl { |
--- |
5672 |
struct AAInstanceInfoReturned final : AAInstanceInfoImpl { |
--- |
| 5673 |
AAInstanceInfoReturned(const IRPosition &IRP, Attributor &A) |
0 |
5673 |
AAInstanceInfoReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 5674 |
: AAInstanceInfoImpl(IRP, A) { |
0 |
5674 |
: AAInstanceInfoImpl(IRP, A) { |
0 |
| 5675 |
llvm_unreachable("InstanceInfo is not applicable to function returns!"); |
0 |
5675 |
llvm_unreachable("InstanceInfo is not applicable to function returns!"); |
0 |
| 5676 |
} |
--- |
5676 |
} |
--- |
| 5677 |
|
--- |
5677 |
|
--- |
| 5678 |
/// See AbstractAttribute::initialize(...). |
--- |
5678 |
/// See AbstractAttribute::initialize(...). |
--- |
| 5679 |
void initialize(Attributor &A) override { |
0 |
5679 |
void initialize(Attributor &A) override { |
0 |
| 5680 |
llvm_unreachable("InstanceInfo is not applicable to function returns!"); |
0 |
5680 |
llvm_unreachable("InstanceInfo is not applicable to function returns!"); |
0 |
| 5681 |
} |
--- |
5681 |
} |
--- |
| 5682 |
|
--- |
5682 |
|
--- |
| 5683 |
/// See AbstractAttribute::updateImpl(...). |
--- |
5683 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 5684 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
5684 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 5685 |
llvm_unreachable("InstanceInfo is not applicable to function returns!"); |
0 |
5685 |
llvm_unreachable("InstanceInfo is not applicable to function returns!"); |
0 |
| 5686 |
} |
--- |
5686 |
} |
--- |
| 5687 |
}; |
--- |
5687 |
}; |
--- |
| 5688 |
|
--- |
5688 |
|
--- |
| 5689 |
/// InstanceInfo attribute deduction for a call site return value. |
--- |
5689 |
/// InstanceInfo attribute deduction for a call site return value. |
--- |
| 5690 |
struct AAInstanceInfoCallSiteReturned final : AAInstanceInfoFloating { |
--- |
5690 |
struct AAInstanceInfoCallSiteReturned final : AAInstanceInfoFloating { |
--- |
| 5691 |
AAInstanceInfoCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
5691 |
AAInstanceInfoCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 5692 |
: AAInstanceInfoFloating(IRP, A) {} |
0 |
5692 |
: AAInstanceInfoFloating(IRP, A) {} |
0 |
| 5693 |
}; |
--- |
5693 |
}; |
--- |
| 5694 |
} // namespace |
--- |
5694 |
} // namespace |
--- |
| 5695 |
|
--- |
5695 |
|
--- |
| 5696 |
/// ----------------------- Variable Capturing --------------------------------- |
--- |
5696 |
/// ----------------------- Variable Capturing --------------------------------- |
--- |
| 5697 |
bool AANoCapture::isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
5697 |
bool AANoCapture::isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
| 5698 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
5698 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 5699 |
bool IgnoreSubsumingPositions) { |
--- |
5699 |
bool IgnoreSubsumingPositions) { |
--- |
| 5700 |
assert(ImpliedAttributeKind == Attribute::NoCapture && |
0 |
5700 |
assert(ImpliedAttributeKind == Attribute::NoCapture && |
0 |
| 5701 |
"Unexpected attribute kind"); |
--- |
5701 |
"Unexpected attribute kind"); |
--- |
| 5702 |
Value &V = IRP.getAssociatedValue(); |
0 |
5702 |
Value &V = IRP.getAssociatedValue(); |
0 |
| 5703 |
if (!IRP.isArgumentPosition()) |
0 |
5703 |
if (!IRP.isArgumentPosition()) |
0 |
| 5704 |
return V.use_empty(); |
0 |
5704 |
return V.use_empty(); |
0 |
| 5705 |
|
--- |
5705 |
|
--- |
| 5706 |
// You cannot "capture" null in the default address space. |
--- |
5706 |
// You cannot "capture" null in the default address space. |
--- |
| 5707 |
if (isa(V) || (isa(V) && |
0 |
5707 |
if (isa(V) || (isa(V) && |
0 |
| 5708 |
V.getType()->getPointerAddressSpace() == 0)) { |
0 |
5708 |
V.getType()->getPointerAddressSpace() == 0)) { |
0 |
| 5709 |
return true; |
0 |
5709 |
return true; |
0 |
| 5710 |
} |
--- |
5710 |
} |
--- |
| 5711 |
|
--- |
5711 |
|
--- |
| 5712 |
if (A.hasAttr(IRP, {Attribute::NoCapture}, |
0 |
5712 |
if (A.hasAttr(IRP, {Attribute::NoCapture}, |
0 |
| 5713 |
/* IgnoreSubsumingPositions */ true, Attribute::NoCapture)) |
--- |
5713 |
/* IgnoreSubsumingPositions */ true, Attribute::NoCapture)) |
--- |
| 5714 |
return true; |
0 |
5714 |
return true; |
0 |
| 5715 |
|
--- |
5715 |
|
--- |
| 5716 |
if (IRP.getPositionKind() == IRP_CALL_SITE_ARGUMENT) |
0 |
5716 |
if (IRP.getPositionKind() == IRP_CALL_SITE_ARGUMENT) |
0 |
| 5717 |
if (Argument *Arg = IRP.getAssociatedArgument()) |
0 |
5717 |
if (Argument *Arg = IRP.getAssociatedArgument()) |
0 |
| 5718 |
if (A.hasAttr(IRPosition::argument(*Arg), |
0 |
5718 |
if (A.hasAttr(IRPosition::argument(*Arg), |
0 |
| 5719 |
{Attribute::NoCapture, Attribute::ByVal}, |
--- |
5719 |
{Attribute::NoCapture, Attribute::ByVal}, |
--- |
| 5720 |
/* IgnoreSubsumingPositions */ true)) { |
--- |
5720 |
/* IgnoreSubsumingPositions */ true)) { |
--- |
| 5721 |
A.manifestAttrs(IRP, |
0 |
5721 |
A.manifestAttrs(IRP, |
0 |
| 5722 |
Attribute::get(V.getContext(), Attribute::NoCapture)); |
0 |
5722 |
Attribute::get(V.getContext(), Attribute::NoCapture)); |
0 |
| 5723 |
return true; |
0 |
5723 |
return true; |
0 |
| 5724 |
} |
--- |
5724 |
} |
--- |
| 5725 |
|
--- |
5725 |
|
--- |
| 5726 |
if (const Function *F = IRP.getAssociatedFunction()) { |
0 |
5726 |
if (const Function *F = IRP.getAssociatedFunction()) { |
0 |
| 5727 |
// Check what state the associated function can actually capture. |
--- |
5727 |
// Check what state the associated function can actually capture. |
--- |
| 5728 |
AANoCapture::StateType State; |
0 |
5728 |
AANoCapture::StateType State; |
0 |
| 5729 |
determineFunctionCaptureCapabilities(IRP, *F, State); |
0 |
5729 |
determineFunctionCaptureCapabilities(IRP, *F, State); |
0 |
| 5730 |
if (State.isKnown(NO_CAPTURE)) { |
0 |
5730 |
if (State.isKnown(NO_CAPTURE)) { |
0 |
| 5731 |
A.manifestAttrs(IRP, |
0 |
5731 |
A.manifestAttrs(IRP, |
0 |
| 5732 |
Attribute::get(V.getContext(), Attribute::NoCapture)); |
0 |
5732 |
Attribute::get(V.getContext(), Attribute::NoCapture)); |
0 |
| 5733 |
return true; |
0 |
5733 |
return true; |
0 |
| 5734 |
} |
--- |
5734 |
} |
--- |
| 5735 |
} |
0 |
5735 |
} |
0 |
| 5736 |
|
--- |
5736 |
|
--- |
| 5737 |
return false; |
0 |
5737 |
return false; |
0 |
| 5738 |
} |
--- |
5738 |
} |
--- |
| 5739 |
|
--- |
5739 |
|
--- |
| 5740 |
/// Set the NOT_CAPTURED_IN_MEM and NOT_CAPTURED_IN_RET bits in \p Known |
--- |
5740 |
/// Set the NOT_CAPTURED_IN_MEM and NOT_CAPTURED_IN_RET bits in \p Known |
--- |
| 5741 |
/// depending on the ability of the function associated with \p IRP to capture |
--- |
5741 |
/// depending on the ability of the function associated with \p IRP to capture |
--- |
| 5742 |
/// state in memory and through "returning/throwing", respectively. |
--- |
5742 |
/// state in memory and through "returning/throwing", respectively. |
--- |
| 5743 |
void AANoCapture::determineFunctionCaptureCapabilities(const IRPosition &IRP, |
0 |
5743 |
void AANoCapture::determineFunctionCaptureCapabilities(const IRPosition &IRP, |
0 |
| 5744 |
const Function &F, |
--- |
5744 |
const Function &F, |
--- |
| 5745 |
BitIntegerState &State) { |
--- |
5745 |
BitIntegerState &State) { |
--- |
| 5746 |
// TODO: Once we have memory behavior attributes we should use them here. |
--- |
5746 |
// TODO: Once we have memory behavior attributes we should use them here. |
--- |
| 5747 |
|
--- |
5747 |
|
--- |
| 5748 |
// If we know we cannot communicate or write to memory, we do not care about |
--- |
5748 |
// If we know we cannot communicate or write to memory, we do not care about |
--- |
| 5749 |
// ptr2int anymore. |
--- |
5749 |
// ptr2int anymore. |
--- |
| 5750 |
bool ReadOnly = F.onlyReadsMemory(); |
0 |
5750 |
bool ReadOnly = F.onlyReadsMemory(); |
0 |
| 5751 |
bool NoThrow = F.doesNotThrow(); |
0 |
5751 |
bool NoThrow = F.doesNotThrow(); |
0 |
| 5752 |
bool IsVoidReturn = F.getReturnType()->isVoidTy(); |
0 |
5752 |
bool IsVoidReturn = F.getReturnType()->isVoidTy(); |
0 |
| 5753 |
if (ReadOnly && NoThrow && IsVoidReturn) { |
0 |
5753 |
if (ReadOnly && NoThrow && IsVoidReturn) { |
0 |
| 5754 |
State.addKnownBits(NO_CAPTURE); |
0 |
5754 |
State.addKnownBits(NO_CAPTURE); |
0 |
| 5755 |
return; |
0 |
5755 |
return; |
0 |
| 5756 |
} |
--- |
5756 |
} |
--- |
| 5757 |
|
--- |
5757 |
|
--- |
| 5758 |
// A function cannot capture state in memory if it only reads memory, it can |
--- |
5758 |
// A function cannot capture state in memory if it only reads memory, it can |
--- |
| 5759 |
// however return/throw state and the state might be influenced by the |
--- |
5759 |
// however return/throw state and the state might be influenced by the |
--- |
| 5760 |
// pointer value, e.g., loading from a returned pointer might reveal a bit. |
--- |
5760 |
// pointer value, e.g., loading from a returned pointer might reveal a bit. |
--- |
| 5761 |
if (ReadOnly) |
0 |
5761 |
if (ReadOnly) |
0 |
| 5762 |
State.addKnownBits(NOT_CAPTURED_IN_MEM); |
0 |
5762 |
State.addKnownBits(NOT_CAPTURED_IN_MEM); |
0 |
| 5763 |
|
--- |
5763 |
|
--- |
| 5764 |
// A function cannot communicate state back if it does not through |
--- |
5764 |
// A function cannot communicate state back if it does not through |
--- |
| 5765 |
// exceptions and doesn not return values. |
--- |
5765 |
// exceptions and doesn not return values. |
--- |
| 5766 |
if (NoThrow && IsVoidReturn) |
0 |
5766 |
if (NoThrow && IsVoidReturn) |
0 |
| 5767 |
State.addKnownBits(NOT_CAPTURED_IN_RET); |
0 |
5767 |
State.addKnownBits(NOT_CAPTURED_IN_RET); |
0 |
| 5768 |
|
--- |
5768 |
|
--- |
| 5769 |
// Check existing "returned" attributes. |
--- |
5769 |
// Check existing "returned" attributes. |
--- |
| 5770 |
int ArgNo = IRP.getCalleeArgNo(); |
0 |
5770 |
int ArgNo = IRP.getCalleeArgNo(); |
0 |
| 5771 |
if (!NoThrow || ArgNo < 0 || |
0 |
5771 |
if (!NoThrow || ArgNo < 0 || |
0 |
| 5772 |
!F.getAttributes().hasAttrSomewhere(Attribute::Returned)) |
0 |
5772 |
!F.getAttributes().hasAttrSomewhere(Attribute::Returned)) |
0 |
| 5773 |
return; |
0 |
5773 |
return; |
0 |
| 5774 |
|
--- |
5774 |
|
--- |
| 5775 |
for (unsigned U = 0, E = F.arg_size(); U < E; ++U) |
0 |
5775 |
for (unsigned U = 0, E = F.arg_size(); U < E; ++U) |
0 |
| 5776 |
if (F.hasParamAttribute(U, Attribute::Returned)) { |
0 |
5776 |
if (F.hasParamAttribute(U, Attribute::Returned)) { |
0 |
| 5777 |
if (U == unsigned(ArgNo)) |
0 |
5777 |
if (U == unsigned(ArgNo)) |
0 |
| 5778 |
State.removeAssumedBits(NOT_CAPTURED_IN_RET); |
0 |
5778 |
State.removeAssumedBits(NOT_CAPTURED_IN_RET); |
0 |
| 5779 |
else if (ReadOnly) |
0 |
5779 |
else if (ReadOnly) |
0 |
| 5780 |
State.addKnownBits(NO_CAPTURE); |
0 |
5780 |
State.addKnownBits(NO_CAPTURE); |
0 |
| 5781 |
else |
--- |
5781 |
else |
--- |
| 5782 |
State.addKnownBits(NOT_CAPTURED_IN_RET); |
0 |
5782 |
State.addKnownBits(NOT_CAPTURED_IN_RET); |
0 |
| 5783 |
break; |
0 |
5783 |
break; |
0 |
| 5784 |
} |
--- |
5784 |
} |
--- |
| 5785 |
} |
--- |
5785 |
} |
--- |
| 5786 |
|
--- |
5786 |
|
--- |
| 5787 |
namespace { |
--- |
5787 |
namespace { |
--- |
| 5788 |
/// A class to hold the state of for no-capture attributes. |
--- |
5788 |
/// A class to hold the state of for no-capture attributes. |
--- |
| 5789 |
struct AANoCaptureImpl : public AANoCapture { |
--- |
5789 |
struct AANoCaptureImpl : public AANoCapture { |
--- |
| 5790 |
AANoCaptureImpl(const IRPosition &IRP, Attributor &A) : AANoCapture(IRP, A) {} |
0 |
5790 |
AANoCaptureImpl(const IRPosition &IRP, Attributor &A) : AANoCapture(IRP, A) {} |
0 |
| 5791 |
|
--- |
5791 |
|
--- |
| 5792 |
/// See AbstractAttribute::initialize(...). |
--- |
5792 |
/// See AbstractAttribute::initialize(...). |
--- |
| 5793 |
void initialize(Attributor &A) override { |
0 |
5793 |
void initialize(Attributor &A) override { |
0 |
| 5794 |
bool IsKnown; |
--- |
5794 |
bool IsKnown; |
--- |
| 5795 |
assert(!AA::hasAssumedIRAttr( |
0 |
5795 |
assert(!AA::hasAssumedIRAttr( |
0 |
| 5796 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
5796 |
A, nullptr, getIRPosition(), DepClassTy::NONE, IsKnown)); |
--- |
| 5797 |
(void)IsKnown; |
--- |
5797 |
(void)IsKnown; |
--- |
| 5798 |
} |
0 |
5798 |
} |
0 |
| 5799 |
|
--- |
5799 |
|
--- |
| 5800 |
/// See AbstractAttribute::updateImpl(...). |
--- |
5800 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 5801 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
5801 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
| 5802 |
|
--- |
5802 |
|
--- |
| 5803 |
/// see AbstractAttribute::isAssumedNoCaptureMaybeReturned(...). |
--- |
5803 |
/// see AbstractAttribute::isAssumedNoCaptureMaybeReturned(...). |
--- |
| 5804 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
5804 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
| 5805 |
SmallVectorImpl &Attrs) const override { |
--- |
5805 |
SmallVectorImpl &Attrs) const override { |
--- |
| 5806 |
if (!isAssumedNoCaptureMaybeReturned()) |
0 |
5806 |
if (!isAssumedNoCaptureMaybeReturned()) |
0 |
| 5807 |
return; |
0 |
5807 |
return; |
0 |
| 5808 |
|
--- |
5808 |
|
--- |
| 5809 |
if (isArgumentPosition()) { |
0 |
5809 |
if (isArgumentPosition()) { |
0 |
| 5810 |
if (isAssumedNoCapture()) |
0 |
5810 |
if (isAssumedNoCapture()) |
0 |
| 5811 |
Attrs.emplace_back(Attribute::get(Ctx, Attribute::NoCapture)); |
0 |
5811 |
Attrs.emplace_back(Attribute::get(Ctx, Attribute::NoCapture)); |
0 |
| 5812 |
else if (ManifestInternal) |
0 |
5812 |
else if (ManifestInternal) |
0 |
| 5813 |
Attrs.emplace_back(Attribute::get(Ctx, "no-capture-maybe-returned")); |
0 |
5813 |
Attrs.emplace_back(Attribute::get(Ctx, "no-capture-maybe-returned")); |
0 |
| 5814 |
} |
--- |
5814 |
} |
--- |
| 5815 |
} |
--- |
5815 |
} |
--- |
| 5816 |
|
--- |
5816 |
|
--- |
| 5817 |
/// See AbstractState::getAsStr(). |
--- |
5817 |
/// See AbstractState::getAsStr(). |
--- |
| 5818 |
const std::string getAsStr(Attributor *A) const override { |
0 |
5818 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 5819 |
if (isKnownNoCapture()) |
0 |
5819 |
if (isKnownNoCapture()) |
0 |
| 5820 |
return "known not-captured"; |
0 |
5820 |
return "known not-captured"; |
0 |
| 5821 |
if (isAssumedNoCapture()) |
0 |
5821 |
if (isAssumedNoCapture()) |
0 |
| 5822 |
return "assumed not-captured"; |
0 |
5822 |
return "assumed not-captured"; |
0 |
| 5823 |
if (isKnownNoCaptureMaybeReturned()) |
0 |
5823 |
if (isKnownNoCaptureMaybeReturned()) |
0 |
| 5824 |
return "known not-captured-maybe-returned"; |
0 |
5824 |
return "known not-captured-maybe-returned"; |
0 |
| 5825 |
if (isAssumedNoCaptureMaybeReturned()) |
0 |
5825 |
if (isAssumedNoCaptureMaybeReturned()) |
0 |
| 5826 |
return "assumed not-captured-maybe-returned"; |
0 |
5826 |
return "assumed not-captured-maybe-returned"; |
0 |
| 5827 |
return "assumed-captured"; |
0 |
5827 |
return "assumed-captured"; |
0 |
| 5828 |
} |
--- |
5828 |
} |
--- |
| 5829 |
|
--- |
5829 |
|
--- |
| 5830 |
/// Check the use \p U and update \p State accordingly. Return true if we |
--- |
5830 |
/// Check the use \p U and update \p State accordingly. Return true if we |
--- |
| 5831 |
/// should continue to update the state. |
--- |
5831 |
/// should continue to update the state. |
--- |
| 5832 |
bool checkUse(Attributor &A, AANoCapture::StateType &State, const Use &U, |
0 |
5832 |
bool checkUse(Attributor &A, AANoCapture::StateType &State, const Use &U, |
0 |
| 5833 |
bool &Follow) { |
--- |
5833 |
bool &Follow) { |
--- |
| 5834 |
Instruction *UInst = cast(U.getUser()); |
0 |
5834 |
Instruction *UInst = cast(U.getUser()); |
0 |
| 5835 |
LLVM_DEBUG(dbgs() << "[AANoCapture] Check use: " << *U.get() << " in " |
0 |
5835 |
LLVM_DEBUG(dbgs() << "[AANoCapture] Check use: " << *U.get() << " in " |
0 |
| 5836 |
<< *UInst << "\n"); |
--- |
5836 |
<< *UInst << "\n"); |
--- |
| 5837 |
|
--- |
5837 |
|
--- |
| 5838 |
// Deal with ptr2int by following uses. |
--- |
5838 |
// Deal with ptr2int by following uses. |
--- |
| 5839 |
if (isa(UInst)) { |
0 |
5839 |
if (isa(UInst)) { |
0 |
| 5840 |
LLVM_DEBUG(dbgs() << " - ptr2int assume the worst!\n"); |
0 |
5840 |
LLVM_DEBUG(dbgs() << " - ptr2int assume the worst!\n"); |
0 |
| 5841 |
return isCapturedIn(State, /* Memory */ true, /* Integer */ true, |
0 |
5841 |
return isCapturedIn(State, /* Memory */ true, /* Integer */ true, |
0 |
| 5842 |
/* Return */ true); |
0 |
5842 |
/* Return */ true); |
0 |
| 5843 |
} |
--- |
5843 |
} |
--- |
| 5844 |
|
--- |
5844 |
|
--- |
| 5845 |
// For stores we already checked if we can follow them, if they make it |
--- |
5845 |
// For stores we already checked if we can follow them, if they make it |
--- |
| 5846 |
// here we give up. |
--- |
5846 |
// here we give up. |
--- |
| 5847 |
if (isa(UInst)) |
0 |
5847 |
if (isa(UInst)) |
0 |
| 5848 |
return isCapturedIn(State, /* Memory */ true, /* Integer */ false, |
0 |
5848 |
return isCapturedIn(State, /* Memory */ true, /* Integer */ false, |
0 |
| 5849 |
/* Return */ false); |
0 |
5849 |
/* Return */ false); |
0 |
| 5850 |
|
--- |
5850 |
|
--- |
| 5851 |
// Explicitly catch return instructions. |
--- |
5851 |
// Explicitly catch return instructions. |
--- |
| 5852 |
if (isa(UInst)) { |
0 |
5852 |
if (isa(UInst)) { |
0 |
| 5853 |
if (UInst->getFunction() == getAnchorScope()) |
0 |
5853 |
if (UInst->getFunction() == getAnchorScope()) |
0 |
| 5854 |
return isCapturedIn(State, /* Memory */ false, /* Integer */ false, |
0 |
5854 |
return isCapturedIn(State, /* Memory */ false, /* Integer */ false, |
0 |
| 5855 |
/* Return */ true); |
0 |
5855 |
/* Return */ true); |
0 |
| 5856 |
return isCapturedIn(State, /* Memory */ true, /* Integer */ true, |
0 |
5856 |
return isCapturedIn(State, /* Memory */ true, /* Integer */ true, |
0 |
| 5857 |
/* Return */ true); |
0 |
5857 |
/* Return */ true); |
0 |
| 5858 |
} |
--- |
5858 |
} |
--- |
| 5859 |
|
--- |
5859 |
|
--- |
| 5860 |
// For now we only use special logic for call sites. However, the tracker |
--- |
5860 |
// For now we only use special logic for call sites. However, the tracker |
--- |
| 5861 |
// itself knows about a lot of other non-capturing cases already. |
--- |
5861 |
// itself knows about a lot of other non-capturing cases already. |
--- |
| 5862 |
auto *CB = dyn_cast(UInst); |
0 |
5862 |
auto *CB = dyn_cast(UInst); |
0 |
| 5863 |
if (!CB || !CB->isArgOperand(&U)) |
0 |
5863 |
if (!CB || !CB->isArgOperand(&U)) |
0 |
| 5864 |
return isCapturedIn(State, /* Memory */ true, /* Integer */ true, |
0 |
5864 |
return isCapturedIn(State, /* Memory */ true, /* Integer */ true, |
0 |
| 5865 |
/* Return */ true); |
0 |
5865 |
/* Return */ true); |
0 |
| 5866 |
|
--- |
5866 |
|
--- |
| 5867 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
5867 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
| 5868 |
const IRPosition &CSArgPos = IRPosition::callsite_argument(*CB, ArgNo); |
0 |
5868 |
const IRPosition &CSArgPos = IRPosition::callsite_argument(*CB, ArgNo); |
0 |
| 5869 |
// If we have a abstract no-capture attribute for the argument we can use |
--- |
5869 |
// If we have a abstract no-capture attribute for the argument we can use |
--- |
| 5870 |
// it to justify a non-capture attribute here. This allows recursion! |
--- |
5870 |
// it to justify a non-capture attribute here. This allows recursion! |
--- |
| 5871 |
bool IsKnownNoCapture; |
--- |
5871 |
bool IsKnownNoCapture; |
--- |
| 5872 |
const AANoCapture *ArgNoCaptureAA = nullptr; |
0 |
5872 |
const AANoCapture *ArgNoCaptureAA = nullptr; |
0 |
| 5873 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
5873 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
| 5874 |
A, this, CSArgPos, DepClassTy::REQUIRED, IsKnownNoCapture, false, |
--- |
5874 |
A, this, CSArgPos, DepClassTy::REQUIRED, IsKnownNoCapture, false, |
--- |
| 5875 |
&ArgNoCaptureAA); |
--- |
5875 |
&ArgNoCaptureAA); |
--- |
| 5876 |
if (IsAssumedNoCapture) |
0 |
5876 |
if (IsAssumedNoCapture) |
0 |
| 5877 |
return isCapturedIn(State, /* Memory */ false, /* Integer */ false, |
0 |
5877 |
return isCapturedIn(State, /* Memory */ false, /* Integer */ false, |
0 |
| 5878 |
/* Return */ false); |
0 |
5878 |
/* Return */ false); |
0 |
| 5879 |
if (ArgNoCaptureAA && ArgNoCaptureAA->isAssumedNoCaptureMaybeReturned()) { |
0 |
5879 |
if (ArgNoCaptureAA && ArgNoCaptureAA->isAssumedNoCaptureMaybeReturned()) { |
0 |
| 5880 |
Follow = true; |
0 |
5880 |
Follow = true; |
0 |
| 5881 |
return isCapturedIn(State, /* Memory */ false, /* Integer */ false, |
0 |
5881 |
return isCapturedIn(State, /* Memory */ false, /* Integer */ false, |
0 |
| 5882 |
/* Return */ false); |
0 |
5882 |
/* Return */ false); |
0 |
| 5883 |
} |
--- |
5883 |
} |
--- |
| 5884 |
|
--- |
5884 |
|
--- |
| 5885 |
// Lastly, we could not find a reason no-capture can be assumed so we don't. |
--- |
5885 |
// Lastly, we could not find a reason no-capture can be assumed so we don't. |
--- |
| 5886 |
return isCapturedIn(State, /* Memory */ true, /* Integer */ true, |
0 |
5886 |
return isCapturedIn(State, /* Memory */ true, /* Integer */ true, |
0 |
| 5887 |
/* Return */ true); |
0 |
5887 |
/* Return */ true); |
0 |
| 5888 |
} |
--- |
5888 |
} |
--- |
| 5889 |
|
--- |
5889 |
|
--- |
| 5890 |
/// Update \p State according to \p CapturedInMem, \p CapturedInInt, and |
--- |
5890 |
/// Update \p State according to \p CapturedInMem, \p CapturedInInt, and |
--- |
| 5891 |
/// \p CapturedInRet, then return true if we should continue updating the |
--- |
5891 |
/// \p CapturedInRet, then return true if we should continue updating the |
--- |
| 5892 |
/// state. |
--- |
5892 |
/// state. |
--- |
| 5893 |
static bool isCapturedIn(AANoCapture::StateType &State, bool CapturedInMem, |
0 |
5893 |
static bool isCapturedIn(AANoCapture::StateType &State, bool CapturedInMem, |
0 |
| 5894 |
bool CapturedInInt, bool CapturedInRet) { |
--- |
5894 |
bool CapturedInInt, bool CapturedInRet) { |
--- |
| 5895 |
LLVM_DEBUG(dbgs() << " - captures [Mem " << CapturedInMem << "|Int " |
0 |
5895 |
LLVM_DEBUG(dbgs() << " - captures [Mem " << CapturedInMem << "|Int " |
0 |
| 5896 |
<< CapturedInInt << "|Ret " << CapturedInRet << "]\n"); |
--- |
5896 |
<< CapturedInInt << "|Ret " << CapturedInRet << "]\n"); |
--- |
| 5897 |
if (CapturedInMem) |
0 |
5897 |
if (CapturedInMem) |
0 |
| 5898 |
State.removeAssumedBits(AANoCapture::NOT_CAPTURED_IN_MEM); |
0 |
5898 |
State.removeAssumedBits(AANoCapture::NOT_CAPTURED_IN_MEM); |
0 |
| 5899 |
if (CapturedInInt) |
0 |
5899 |
if (CapturedInInt) |
0 |
| 5900 |
State.removeAssumedBits(AANoCapture::NOT_CAPTURED_IN_INT); |
0 |
5900 |
State.removeAssumedBits(AANoCapture::NOT_CAPTURED_IN_INT); |
0 |
| 5901 |
if (CapturedInRet) |
0 |
5901 |
if (CapturedInRet) |
0 |
| 5902 |
State.removeAssumedBits(AANoCapture::NOT_CAPTURED_IN_RET); |
0 |
5902 |
State.removeAssumedBits(AANoCapture::NOT_CAPTURED_IN_RET); |
0 |
| 5903 |
return State.isAssumed(AANoCapture::NO_CAPTURE_MAYBE_RETURNED); |
0 |
5903 |
return State.isAssumed(AANoCapture::NO_CAPTURE_MAYBE_RETURNED); |
0 |
| 5904 |
} |
--- |
5904 |
} |
--- |
| 5905 |
}; |
--- |
5905 |
}; |
--- |
| 5906 |
|
--- |
5906 |
|
--- |
| 5907 |
ChangeStatus AANoCaptureImpl::updateImpl(Attributor &A) { |
0 |
5907 |
ChangeStatus AANoCaptureImpl::updateImpl(Attributor &A) { |
0 |
| 5908 |
const IRPosition &IRP = getIRPosition(); |
0 |
5908 |
const IRPosition &IRP = getIRPosition(); |
0 |
| 5909 |
Value *V = isArgumentPosition() ? IRP.getAssociatedArgument() |
0 |
5909 |
Value *V = isArgumentPosition() ? IRP.getAssociatedArgument() |
0 |
| 5910 |
: &IRP.getAssociatedValue(); |
0 |
5910 |
: &IRP.getAssociatedValue(); |
0 |
| 5911 |
if (!V) |
0 |
5911 |
if (!V) |
0 |
| 5912 |
return indicatePessimisticFixpoint(); |
0 |
5912 |
return indicatePessimisticFixpoint(); |
0 |
| 5913 |
|
--- |
5913 |
|
--- |
| 5914 |
const Function *F = |
--- |
5914 |
const Function *F = |
--- |
| 5915 |
isArgumentPosition() ? IRP.getAssociatedFunction() : IRP.getAnchorScope(); |
0 |
5915 |
isArgumentPosition() ? IRP.getAssociatedFunction() : IRP.getAnchorScope(); |
0 |
| 5916 |
assert(F && "Expected a function!"); |
0 |
5916 |
assert(F && "Expected a function!"); |
0 |
| 5917 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
5917 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
| 5918 |
|
--- |
5918 |
|
--- |
| 5919 |
AANoCapture::StateType T; |
0 |
5919 |
AANoCapture::StateType T; |
0 |
| 5920 |
|
--- |
5920 |
|
--- |
| 5921 |
// Readonly means we cannot capture through memory. |
--- |
5921 |
// Readonly means we cannot capture through memory. |
--- |
| 5922 |
bool IsKnown; |
--- |
5922 |
bool IsKnown; |
--- |
| 5923 |
if (AA::isAssumedReadOnly(A, FnPos, *this, IsKnown)) { |
0 |
5923 |
if (AA::isAssumedReadOnly(A, FnPos, *this, IsKnown)) { |
0 |
| 5924 |
T.addKnownBits(NOT_CAPTURED_IN_MEM); |
0 |
5924 |
T.addKnownBits(NOT_CAPTURED_IN_MEM); |
0 |
| 5925 |
if (IsKnown) |
0 |
5925 |
if (IsKnown) |
0 |
| 5926 |
addKnownBits(NOT_CAPTURED_IN_MEM); |
0 |
5926 |
addKnownBits(NOT_CAPTURED_IN_MEM); |
0 |
| 5927 |
} |
--- |
5927 |
} |
--- |
| 5928 |
|
--- |
5928 |
|
--- |
| 5929 |
// Make sure all returned values are different than the underlying value. |
--- |
5929 |
// Make sure all returned values are different than the underlying value. |
--- |
| 5930 |
// TODO: we could do this in a more sophisticated way inside |
--- |
5930 |
// TODO: we could do this in a more sophisticated way inside |
--- |
| 5931 |
// AAReturnedValues, e.g., track all values that escape through returns |
--- |
5931 |
// AAReturnedValues, e.g., track all values that escape through returns |
--- |
| 5932 |
// directly somehow. |
--- |
5932 |
// directly somehow. |
--- |
| 5933 |
auto CheckReturnedArgs = [&](bool &UsedAssumedInformation) { |
0 |
5933 |
auto CheckReturnedArgs = [&](bool &UsedAssumedInformation) { |
0 |
| 5934 |
SmallVector Values; |
0 |
5934 |
SmallVector Values; |
0 |
| 5935 |
if (!A.getAssumedSimplifiedValues(IRPosition::returned(*F), this, Values, |
0 |
5935 |
if (!A.getAssumedSimplifiedValues(IRPosition::returned(*F), this, Values, |
0 |
| 5936 |
AA::ValueScope::Intraprocedural, |
--- |
5936 |
AA::ValueScope::Intraprocedural, |
--- |
| 5937 |
UsedAssumedInformation)) |
--- |
5937 |
UsedAssumedInformation)) |
--- |
| 5938 |
return false; |
0 |
5938 |
return false; |
0 |
| 5939 |
bool SeenConstant = false; |
0 |
5939 |
bool SeenConstant = false; |
0 |
| 5940 |
for (const AA::ValueAndContext &VAC : Values) { |
0 |
5940 |
for (const AA::ValueAndContext &VAC : Values) { |
0 |
| 5941 |
if (isa(VAC.getValue())) { |
0 |
5941 |
if (isa(VAC.getValue())) { |
0 |
| 5942 |
if (SeenConstant) |
0 |
5942 |
if (SeenConstant) |
0 |
| 5943 |
return false; |
0 |
5943 |
return false; |
0 |
| 5944 |
SeenConstant = true; |
0 |
5944 |
SeenConstant = true; |
0 |
| 5945 |
} else if (!isa(VAC.getValue()) || |
0 |
5945 |
} else if (!isa(VAC.getValue()) || |
0 |
| 5946 |
VAC.getValue() == getAssociatedArgument()) |
0 |
5946 |
VAC.getValue() == getAssociatedArgument()) |
0 |
| 5947 |
return false; |
0 |
5947 |
return false; |
0 |
| 5948 |
} |
--- |
5948 |
} |
--- |
| 5949 |
return true; |
0 |
5949 |
return true; |
0 |
| 5950 |
}; |
0 |
5950 |
}; |
0 |
| 5951 |
|
--- |
5951 |
|
--- |
| 5952 |
bool IsKnownNoUnwind; |
--- |
5952 |
bool IsKnownNoUnwind; |
--- |
| 5953 |
if (AA::hasAssumedIRAttr( |
0 |
5953 |
if (AA::hasAssumedIRAttr( |
0 |
| 5954 |
A, this, FnPos, DepClassTy::OPTIONAL, IsKnownNoUnwind)) { |
--- |
5954 |
A, this, FnPos, DepClassTy::OPTIONAL, IsKnownNoUnwind)) { |
--- |
| 5955 |
bool IsVoidTy = F->getReturnType()->isVoidTy(); |
0 |
5955 |
bool IsVoidTy = F->getReturnType()->isVoidTy(); |
0 |
| 5956 |
bool UsedAssumedInformation = false; |
0 |
5956 |
bool UsedAssumedInformation = false; |
0 |
| 5957 |
if (IsVoidTy || CheckReturnedArgs(UsedAssumedInformation)) { |
0 |
5957 |
if (IsVoidTy || CheckReturnedArgs(UsedAssumedInformation)) { |
0 |
| 5958 |
T.addKnownBits(NOT_CAPTURED_IN_RET); |
0 |
5958 |
T.addKnownBits(NOT_CAPTURED_IN_RET); |
0 |
| 5959 |
if (T.isKnown(NOT_CAPTURED_IN_MEM)) |
0 |
5959 |
if (T.isKnown(NOT_CAPTURED_IN_MEM)) |
0 |
| 5960 |
return ChangeStatus::UNCHANGED; |
0 |
5960 |
return ChangeStatus::UNCHANGED; |
0 |
| 5961 |
if (IsKnownNoUnwind && (IsVoidTy || !UsedAssumedInformation)) { |
0 |
5961 |
if (IsKnownNoUnwind && (IsVoidTy || !UsedAssumedInformation)) { |
0 |
| 5962 |
addKnownBits(NOT_CAPTURED_IN_RET); |
0 |
5962 |
addKnownBits(NOT_CAPTURED_IN_RET); |
0 |
| 5963 |
if (isKnown(NOT_CAPTURED_IN_MEM)) |
0 |
5963 |
if (isKnown(NOT_CAPTURED_IN_MEM)) |
0 |
| 5964 |
return indicateOptimisticFixpoint(); |
0 |
5964 |
return indicateOptimisticFixpoint(); |
0 |
| 5965 |
} |
--- |
5965 |
} |
--- |
| 5966 |
} |
--- |
5966 |
} |
--- |
| 5967 |
} |
--- |
5967 |
} |
--- |
| 5968 |
|
--- |
5968 |
|
--- |
| 5969 |
auto IsDereferenceableOrNull = [&](Value *O, const DataLayout &DL) { |
0 |
5969 |
auto IsDereferenceableOrNull = [&](Value *O, const DataLayout &DL) { |
0 |
| 5970 |
const auto *DerefAA = A.getAAFor( |
0 |
5970 |
const auto *DerefAA = A.getAAFor( |
0 |
| 5971 |
*this, IRPosition::value(*O), DepClassTy::OPTIONAL); |
0 |
5971 |
*this, IRPosition::value(*O), DepClassTy::OPTIONAL); |
0 |
| 5972 |
return DerefAA && DerefAA->getAssumedDereferenceableBytes(); |
0 |
5972 |
return DerefAA && DerefAA->getAssumedDereferenceableBytes(); |
0 |
| 5973 |
}; |
0 |
5973 |
}; |
0 |
| 5974 |
|
--- |
5974 |
|
--- |
| 5975 |
auto UseCheck = [&](const Use &U, bool &Follow) -> bool { |
0 |
5975 |
auto UseCheck = [&](const Use &U, bool &Follow) -> bool { |
0 |
| 5976 |
switch (DetermineUseCaptureKind(U, IsDereferenceableOrNull)) { |
0 |
5976 |
switch (DetermineUseCaptureKind(U, IsDereferenceableOrNull)) { |
0 |
| 5977 |
case UseCaptureKind::NO_CAPTURE: |
0 |
5977 |
case UseCaptureKind::NO_CAPTURE: |
0 |
| 5978 |
return true; |
0 |
5978 |
return true; |
0 |
| 5979 |
case UseCaptureKind::MAY_CAPTURE: |
0 |
5979 |
case UseCaptureKind::MAY_CAPTURE: |
0 |
| 5980 |
return checkUse(A, T, U, Follow); |
0 |
5980 |
return checkUse(A, T, U, Follow); |
0 |
| 5981 |
case UseCaptureKind::PASSTHROUGH: |
0 |
5981 |
case UseCaptureKind::PASSTHROUGH: |
0 |
| 5982 |
Follow = true; |
0 |
5982 |
Follow = true; |
0 |
| 5983 |
return true; |
0 |
5983 |
return true; |
0 |
| 5984 |
} |
--- |
5984 |
} |
--- |
| 5985 |
llvm_unreachable("Unexpected use capture kind!"); |
0 |
5985 |
llvm_unreachable("Unexpected use capture kind!"); |
0 |
| 5986 |
}; |
0 |
5986 |
}; |
0 |
| 5987 |
|
--- |
5987 |
|
--- |
| 5988 |
if (!A.checkForAllUses(UseCheck, *this, *V)) |
0 |
5988 |
if (!A.checkForAllUses(UseCheck, *this, *V)) |
0 |
| 5989 |
return indicatePessimisticFixpoint(); |
0 |
5989 |
return indicatePessimisticFixpoint(); |
0 |
| 5990 |
|
--- |
5990 |
|
--- |
| 5991 |
AANoCapture::StateType &S = getState(); |
0 |
5991 |
AANoCapture::StateType &S = getState(); |
0 |
| 5992 |
auto Assumed = S.getAssumed(); |
0 |
5992 |
auto Assumed = S.getAssumed(); |
0 |
| 5993 |
S.intersectAssumedBits(T.getAssumed()); |
0 |
5993 |
S.intersectAssumedBits(T.getAssumed()); |
0 |
| 5994 |
if (!isAssumedNoCaptureMaybeReturned()) |
0 |
5994 |
if (!isAssumedNoCaptureMaybeReturned()) |
0 |
| 5995 |
return indicatePessimisticFixpoint(); |
0 |
5995 |
return indicatePessimisticFixpoint(); |
0 |
| 5996 |
return Assumed == S.getAssumed() ? ChangeStatus::UNCHANGED |
0 |
5996 |
return Assumed == S.getAssumed() ? ChangeStatus::UNCHANGED |
0 |
| 5997 |
: ChangeStatus::CHANGED; |
0 |
5997 |
: ChangeStatus::CHANGED; |
0 |
| 5998 |
} |
0 |
5998 |
} |
0 |
| 5999 |
|
--- |
5999 |
|
--- |
| 6000 |
/// NoCapture attribute for function arguments. |
--- |
6000 |
/// NoCapture attribute for function arguments. |
--- |
| 6001 |
struct AANoCaptureArgument final : AANoCaptureImpl { |
--- |
6001 |
struct AANoCaptureArgument final : AANoCaptureImpl { |
--- |
| 6002 |
AANoCaptureArgument(const IRPosition &IRP, Attributor &A) |
0 |
6002 |
AANoCaptureArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 6003 |
: AANoCaptureImpl(IRP, A) {} |
0 |
6003 |
: AANoCaptureImpl(IRP, A) {} |
0 |
| 6004 |
|
--- |
6004 |
|
--- |
| 6005 |
/// See AbstractAttribute::trackStatistics() |
--- |
6005 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 6006 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(nocapture) } |
0 |
6006 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(nocapture) } |
0 |
| 6007 |
}; |
--- |
6007 |
}; |
--- |
| 6008 |
|
--- |
6008 |
|
--- |
| 6009 |
/// NoCapture attribute for call site arguments. |
--- |
6009 |
/// NoCapture attribute for call site arguments. |
--- |
| 6010 |
struct AANoCaptureCallSiteArgument final : AANoCaptureImpl { |
--- |
6010 |
struct AANoCaptureCallSiteArgument final : AANoCaptureImpl { |
--- |
| 6011 |
AANoCaptureCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
6011 |
AANoCaptureCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 6012 |
: AANoCaptureImpl(IRP, A) {} |
0 |
6012 |
: AANoCaptureImpl(IRP, A) {} |
0 |
| 6013 |
|
--- |
6013 |
|
--- |
| 6014 |
/// See AbstractAttribute::updateImpl(...). |
--- |
6014 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 6015 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
6015 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 6016 |
// TODO: Once we have call site specific value information we can provide |
--- |
6016 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 6017 |
// call site specific liveness information and then it makes |
--- |
6017 |
// call site specific liveness information and then it makes |
--- |
| 6018 |
// sense to specialize attributes for call sites arguments instead of |
--- |
6018 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 6019 |
// redirecting requests to the callee argument. |
--- |
6019 |
// redirecting requests to the callee argument. |
--- |
| 6020 |
Argument *Arg = getAssociatedArgument(); |
0 |
6020 |
Argument *Arg = getAssociatedArgument(); |
0 |
| 6021 |
if (!Arg) |
0 |
6021 |
if (!Arg) |
0 |
| 6022 |
return indicatePessimisticFixpoint(); |
0 |
6022 |
return indicatePessimisticFixpoint(); |
0 |
| 6023 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
6023 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
| 6024 |
bool IsKnownNoCapture; |
--- |
6024 |
bool IsKnownNoCapture; |
--- |
| 6025 |
const AANoCapture *ArgAA = nullptr; |
0 |
6025 |
const AANoCapture *ArgAA = nullptr; |
0 |
| 6026 |
if (AA::hasAssumedIRAttr( |
0 |
6026 |
if (AA::hasAssumedIRAttr( |
0 |
| 6027 |
A, this, ArgPos, DepClassTy::REQUIRED, IsKnownNoCapture, false, |
--- |
6027 |
A, this, ArgPos, DepClassTy::REQUIRED, IsKnownNoCapture, false, |
--- |
| 6028 |
&ArgAA)) |
--- |
6028 |
&ArgAA)) |
--- |
| 6029 |
return ChangeStatus::UNCHANGED; |
0 |
6029 |
return ChangeStatus::UNCHANGED; |
0 |
| 6030 |
if (!ArgAA || !ArgAA->isAssumedNoCaptureMaybeReturned()) |
0 |
6030 |
if (!ArgAA || !ArgAA->isAssumedNoCaptureMaybeReturned()) |
0 |
| 6031 |
return indicatePessimisticFixpoint(); |
0 |
6031 |
return indicatePessimisticFixpoint(); |
0 |
| 6032 |
return clampStateAndIndicateChange(getState(), ArgAA->getState()); |
0 |
6032 |
return clampStateAndIndicateChange(getState(), ArgAA->getState()); |
0 |
| 6033 |
} |
--- |
6033 |
} |
--- |
| 6034 |
|
--- |
6034 |
|
--- |
| 6035 |
/// See AbstractAttribute::trackStatistics() |
--- |
6035 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 6036 |
void trackStatistics() const override{STATS_DECLTRACK_CSARG_ATTR(nocapture)}; |
0 |
6036 |
void trackStatistics() const override{STATS_DECLTRACK_CSARG_ATTR(nocapture)}; |
0 |
| 6037 |
}; |
--- |
6037 |
}; |
--- |
| 6038 |
|
--- |
6038 |
|
--- |
| 6039 |
/// NoCapture attribute for floating values. |
--- |
6039 |
/// NoCapture attribute for floating values. |
--- |
| 6040 |
struct AANoCaptureFloating final : AANoCaptureImpl { |
--- |
6040 |
struct AANoCaptureFloating final : AANoCaptureImpl { |
--- |
| 6041 |
AANoCaptureFloating(const IRPosition &IRP, Attributor &A) |
0 |
6041 |
AANoCaptureFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 6042 |
: AANoCaptureImpl(IRP, A) {} |
0 |
6042 |
: AANoCaptureImpl(IRP, A) {} |
0 |
| 6043 |
|
--- |
6043 |
|
--- |
| 6044 |
/// See AbstractAttribute::trackStatistics() |
--- |
6044 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 6045 |
void trackStatistics() const override { |
0 |
6045 |
void trackStatistics() const override { |
0 |
| 6046 |
STATS_DECLTRACK_FLOATING_ATTR(nocapture) |
0 |
6046 |
STATS_DECLTRACK_FLOATING_ATTR(nocapture) |
0 |
| 6047 |
} |
0 |
6047 |
} |
0 |
| 6048 |
}; |
--- |
6048 |
}; |
--- |
| 6049 |
|
--- |
6049 |
|
--- |
| 6050 |
/// NoCapture attribute for function return value. |
--- |
6050 |
/// NoCapture attribute for function return value. |
--- |
| 6051 |
struct AANoCaptureReturned final : AANoCaptureImpl { |
--- |
6051 |
struct AANoCaptureReturned final : AANoCaptureImpl { |
--- |
| 6052 |
AANoCaptureReturned(const IRPosition &IRP, Attributor &A) |
0 |
6052 |
AANoCaptureReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 6053 |
: AANoCaptureImpl(IRP, A) { |
0 |
6053 |
: AANoCaptureImpl(IRP, A) { |
0 |
| 6054 |
llvm_unreachable("NoCapture is not applicable to function returns!"); |
0 |
6054 |
llvm_unreachable("NoCapture is not applicable to function returns!"); |
0 |
| 6055 |
} |
--- |
6055 |
} |
--- |
| 6056 |
|
--- |
6056 |
|
--- |
| 6057 |
/// See AbstractAttribute::initialize(...). |
--- |
6057 |
/// See AbstractAttribute::initialize(...). |
--- |
| 6058 |
void initialize(Attributor &A) override { |
0 |
6058 |
void initialize(Attributor &A) override { |
0 |
| 6059 |
llvm_unreachable("NoCapture is not applicable to function returns!"); |
0 |
6059 |
llvm_unreachable("NoCapture is not applicable to function returns!"); |
0 |
| 6060 |
} |
--- |
6060 |
} |
--- |
| 6061 |
|
--- |
6061 |
|
--- |
| 6062 |
/// See AbstractAttribute::updateImpl(...). |
--- |
6062 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 6063 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
6063 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 6064 |
llvm_unreachable("NoCapture is not applicable to function returns!"); |
0 |
6064 |
llvm_unreachable("NoCapture is not applicable to function returns!"); |
0 |
| 6065 |
} |
--- |
6065 |
} |
--- |
| 6066 |
|
--- |
6066 |
|
--- |
| 6067 |
/// See AbstractAttribute::trackStatistics() |
--- |
6067 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 6068 |
void trackStatistics() const override {} |
0 |
6068 |
void trackStatistics() const override {} |
0 |
| 6069 |
}; |
--- |
6069 |
}; |
--- |
| 6070 |
|
--- |
6070 |
|
--- |
| 6071 |
/// NoCapture attribute deduction for a call site return value. |
--- |
6071 |
/// NoCapture attribute deduction for a call site return value. |
--- |
| 6072 |
struct AANoCaptureCallSiteReturned final : AANoCaptureImpl { |
--- |
6072 |
struct AANoCaptureCallSiteReturned final : AANoCaptureImpl { |
--- |
| 6073 |
AANoCaptureCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
6073 |
AANoCaptureCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 6074 |
: AANoCaptureImpl(IRP, A) {} |
0 |
6074 |
: AANoCaptureImpl(IRP, A) {} |
0 |
| 6075 |
|
--- |
6075 |
|
--- |
| 6076 |
/// See AbstractAttribute::initialize(...). |
--- |
6076 |
/// See AbstractAttribute::initialize(...). |
--- |
| 6077 |
void initialize(Attributor &A) override { |
0 |
6077 |
void initialize(Attributor &A) override { |
0 |
| 6078 |
const Function *F = getAnchorScope(); |
0 |
6078 |
const Function *F = getAnchorScope(); |
0 |
| 6079 |
// Check what state the associated function can actually capture. |
--- |
6079 |
// Check what state the associated function can actually capture. |
--- |
| 6080 |
determineFunctionCaptureCapabilities(getIRPosition(), *F, *this); |
0 |
6080 |
determineFunctionCaptureCapabilities(getIRPosition(), *F, *this); |
0 |
| 6081 |
} |
0 |
6081 |
} |
0 |
| 6082 |
|
--- |
6082 |
|
--- |
| 6083 |
/// See AbstractAttribute::trackStatistics() |
--- |
6083 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 6084 |
void trackStatistics() const override { |
0 |
6084 |
void trackStatistics() const override { |
0 |
| 6085 |
STATS_DECLTRACK_CSRET_ATTR(nocapture) |
0 |
6085 |
STATS_DECLTRACK_CSRET_ATTR(nocapture) |
0 |
| 6086 |
} |
0 |
6086 |
} |
0 |
| 6087 |
}; |
--- |
6087 |
}; |
--- |
| 6088 |
} // namespace |
--- |
6088 |
} // namespace |
--- |
| 6089 |
|
--- |
6089 |
|
--- |
| 6090 |
/// ------------------ Value Simplify Attribute ---------------------------- |
--- |
6090 |
/// ------------------ Value Simplify Attribute ---------------------------- |
--- |
| 6091 |
|
--- |
6091 |
|
--- |
| 6092 |
bool ValueSimplifyStateType::unionAssumed(std::optional Other) { |
0 |
6092 |
bool ValueSimplifyStateType::unionAssumed(std::optional Other) { |
0 |
| 6093 |
// FIXME: Add a typecast support. |
--- |
6093 |
// FIXME: Add a typecast support. |
--- |
| 6094 |
SimplifiedAssociatedValue = AA::combineOptionalValuesInAAValueLatice( |
0 |
6094 |
SimplifiedAssociatedValue = AA::combineOptionalValuesInAAValueLatice( |
0 |
| 6095 |
SimplifiedAssociatedValue, Other, Ty); |
0 |
6095 |
SimplifiedAssociatedValue, Other, Ty); |
0 |
| 6096 |
if (SimplifiedAssociatedValue == std::optional(nullptr)) |
0 |
6096 |
if (SimplifiedAssociatedValue == std::optional(nullptr)) |
0 |
| 6097 |
return false; |
0 |
6097 |
return false; |
0 |
| 6098 |
|
--- |
6098 |
|
--- |
| 6099 |
LLVM_DEBUG({ |
0 |
6099 |
LLVM_DEBUG({ |
0 |
| 6100 |
if (SimplifiedAssociatedValue) |
--- |
6100 |
if (SimplifiedAssociatedValue) |
--- |
| 6101 |
dbgs() << "[ValueSimplify] is assumed to be " |
--- |
6101 |
dbgs() << "[ValueSimplify] is assumed to be " |
--- |
| 6102 |
<< **SimplifiedAssociatedValue << "\n"; |
--- |
6102 |
<< **SimplifiedAssociatedValue << "\n"; |
--- |
| 6103 |
else |
--- |
6103 |
else |
--- |
| 6104 |
dbgs() << "[ValueSimplify] is assumed to be \n"; |
--- |
6104 |
dbgs() << "[ValueSimplify] is assumed to be \n"; |
--- |
| 6105 |
}); |
--- |
6105 |
}); |
--- |
| 6106 |
return true; |
0 |
6106 |
return true; |
0 |
| 6107 |
} |
--- |
6107 |
} |
--- |
| 6108 |
|
--- |
6108 |
|
--- |
| 6109 |
namespace { |
--- |
6109 |
namespace { |
--- |
| 6110 |
struct AAValueSimplifyImpl : AAValueSimplify { |
--- |
6110 |
struct AAValueSimplifyImpl : AAValueSimplify { |
--- |
| 6111 |
AAValueSimplifyImpl(const IRPosition &IRP, Attributor &A) |
0 |
6111 |
AAValueSimplifyImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 6112 |
: AAValueSimplify(IRP, A) {} |
0 |
6112 |
: AAValueSimplify(IRP, A) {} |
0 |
| 6113 |
|
--- |
6113 |
|
--- |
| 6114 |
/// See AbstractAttribute::initialize(...). |
--- |
6114 |
/// See AbstractAttribute::initialize(...). |
--- |
| 6115 |
void initialize(Attributor &A) override { |
0 |
6115 |
void initialize(Attributor &A) override { |
0 |
| 6116 |
if (getAssociatedValue().getType()->isVoidTy()) |
0 |
6116 |
if (getAssociatedValue().getType()->isVoidTy()) |
0 |
| 6117 |
indicatePessimisticFixpoint(); |
0 |
6117 |
indicatePessimisticFixpoint(); |
0 |
| 6118 |
if (A.hasSimplificationCallback(getIRPosition())) |
0 |
6118 |
if (A.hasSimplificationCallback(getIRPosition())) |
0 |
| 6119 |
indicatePessimisticFixpoint(); |
0 |
6119 |
indicatePessimisticFixpoint(); |
0 |
| 6120 |
} |
0 |
6120 |
} |
0 |
| 6121 |
|
--- |
6121 |
|
--- |
| 6122 |
/// See AbstractAttribute::getAsStr(). |
--- |
6122 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 6123 |
const std::string getAsStr(Attributor *A) const override { |
0 |
6123 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 6124 |
LLVM_DEBUG({ |
0 |
6124 |
LLVM_DEBUG({ |
0 |
| 6125 |
dbgs() << "SAV: " << (bool)SimplifiedAssociatedValue << " "; |
--- |
6125 |
dbgs() << "SAV: " << (bool)SimplifiedAssociatedValue << " "; |
--- |
| 6126 |
if (SimplifiedAssociatedValue && *SimplifiedAssociatedValue) |
--- |
6126 |
if (SimplifiedAssociatedValue && *SimplifiedAssociatedValue) |
--- |
| 6127 |
dbgs() << "SAV: " << **SimplifiedAssociatedValue << " "; |
--- |
6127 |
dbgs() << "SAV: " << **SimplifiedAssociatedValue << " "; |
--- |
| 6128 |
}); |
--- |
6128 |
}); |
--- |
| 6129 |
return isValidState() ? (isAtFixpoint() ? "simplified" : "maybe-simple") |
0 |
6129 |
return isValidState() ? (isAtFixpoint() ? "simplified" : "maybe-simple") |
0 |
| 6130 |
: "not-simple"; |
0 |
6130 |
: "not-simple"; |
0 |
| 6131 |
} |
--- |
6131 |
} |
--- |
| 6132 |
|
--- |
6132 |
|
--- |
| 6133 |
/// See AbstractAttribute::trackStatistics() |
--- |
6133 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 6134 |
void trackStatistics() const override {} |
0 |
6134 |
void trackStatistics() const override {} |
0 |
| 6135 |
|
--- |
6135 |
|
--- |
| 6136 |
/// See AAValueSimplify::getAssumedSimplifiedValue() |
--- |
6136 |
/// See AAValueSimplify::getAssumedSimplifiedValue() |
--- |
| 6137 |
std::optional |
--- |
6137 |
std::optional |
--- |
| 6138 |
getAssumedSimplifiedValue(Attributor &A) const override { |
0 |
6138 |
getAssumedSimplifiedValue(Attributor &A) const override { |
0 |
| 6139 |
return SimplifiedAssociatedValue; |
0 |
6139 |
return SimplifiedAssociatedValue; |
0 |
| 6140 |
} |
--- |
6140 |
} |
--- |
| 6141 |
|
--- |
6141 |
|
--- |
| 6142 |
/// Ensure the return value is \p V with type \p Ty, if not possible return |
--- |
6142 |
/// Ensure the return value is \p V with type \p Ty, if not possible return |
--- |
| 6143 |
/// nullptr. If \p Check is true we will only verify such an operation would |
--- |
6143 |
/// nullptr. If \p Check is true we will only verify such an operation would |
--- |
| 6144 |
/// suceed and return a non-nullptr value if that is the case. No IR is |
--- |
6144 |
/// suceed and return a non-nullptr value if that is the case. No IR is |
--- |
| 6145 |
/// generated or modified. |
--- |
6145 |
/// generated or modified. |
--- |
| 6146 |
static Value *ensureType(Attributor &A, Value &V, Type &Ty, Instruction *CtxI, |
0 |
6146 |
static Value *ensureType(Attributor &A, Value &V, Type &Ty, Instruction *CtxI, |
0 |
| 6147 |
bool Check) { |
--- |
6147 |
bool Check) { |
--- |
| 6148 |
if (auto *TypedV = AA::getWithType(V, Ty)) |
0 |
6148 |
if (auto *TypedV = AA::getWithType(V, Ty)) |
0 |
| 6149 |
return TypedV; |
0 |
6149 |
return TypedV; |
0 |
| 6150 |
if (CtxI && V.getType()->canLosslesslyBitCastTo(&Ty)) |
0 |
6150 |
if (CtxI && V.getType()->canLosslesslyBitCastTo(&Ty)) |
0 |
| 6151 |
return Check ? &V |
0 |
6151 |
return Check ? &V |
0 |
| 6152 |
: BitCastInst::CreatePointerBitCastOrAddrSpaceCast(&V, &Ty, |
0 |
6152 |
: BitCastInst::CreatePointerBitCastOrAddrSpaceCast(&V, &Ty, |
0 |
| 6153 |
"", CtxI); |
0 |
6153 |
"", CtxI); |
0 |
| 6154 |
return nullptr; |
0 |
6154 |
return nullptr; |
0 |
| 6155 |
} |
--- |
6155 |
} |
--- |
| 6156 |
|
--- |
6156 |
|
--- |
| 6157 |
/// Reproduce \p I with type \p Ty or return nullptr if that is not posisble. |
--- |
6157 |
/// Reproduce \p I with type \p Ty or return nullptr if that is not posisble. |
--- |
| 6158 |
/// If \p Check is true we will only verify such an operation would suceed and |
--- |
6158 |
/// If \p Check is true we will only verify such an operation would suceed and |
--- |
| 6159 |
/// return a non-nullptr value if that is the case. No IR is generated or |
--- |
6159 |
/// return a non-nullptr value if that is the case. No IR is generated or |
--- |
| 6160 |
/// modified. |
--- |
6160 |
/// modified. |
--- |
| 6161 |
static Value *reproduceInst(Attributor &A, |
0 |
6161 |
static Value *reproduceInst(Attributor &A, |
0 |
| 6162 |
const AbstractAttribute &QueryingAA, |
--- |
6162 |
const AbstractAttribute &QueryingAA, |
--- |
| 6163 |
Instruction &I, Type &Ty, Instruction *CtxI, |
--- |
6163 |
Instruction &I, Type &Ty, Instruction *CtxI, |
--- |
| 6164 |
bool Check, ValueToValueMapTy &VMap) { |
--- |
6164 |
bool Check, ValueToValueMapTy &VMap) { |
--- |
| 6165 |
assert(CtxI && "Cannot reproduce an instruction without context!"); |
0 |
6165 |
assert(CtxI && "Cannot reproduce an instruction without context!"); |
0 |
| 6166 |
if (Check && (I.mayReadFromMemory() || |
0 |
6166 |
if (Check && (I.mayReadFromMemory() || |
0 |
| 6167 |
!isSafeToSpeculativelyExecute(&I, CtxI, /* DT */ nullptr, |
0 |
6167 |
!isSafeToSpeculativelyExecute(&I, CtxI, /* DT */ nullptr, |
0 |
| 6168 |
/* TLI */ nullptr))) |
--- |
6168 |
/* TLI */ nullptr))) |
--- |
| 6169 |
return nullptr; |
0 |
6169 |
return nullptr; |
0 |
| 6170 |
for (Value *Op : I.operands()) { |
0 |
6170 |
for (Value *Op : I.operands()) { |
0 |
| 6171 |
Value *NewOp = reproduceValue(A, QueryingAA, *Op, Ty, CtxI, Check, VMap); |
0 |
6171 |
Value *NewOp = reproduceValue(A, QueryingAA, *Op, Ty, CtxI, Check, VMap); |
0 |
| 6172 |
if (!NewOp) { |
0 |
6172 |
if (!NewOp) { |
0 |
| 6173 |
assert(Check && "Manifest of new value unexpectedly failed!"); |
0 |
6173 |
assert(Check && "Manifest of new value unexpectedly failed!"); |
0 |
| 6174 |
return nullptr; |
0 |
6174 |
return nullptr; |
0 |
| 6175 |
} |
--- |
6175 |
} |
--- |
| 6176 |
if (!Check) |
0 |
6176 |
if (!Check) |
0 |
| 6177 |
VMap[Op] = NewOp; |
0 |
6177 |
VMap[Op] = NewOp; |
0 |
| 6178 |
} |
--- |
6178 |
} |
--- |
| 6179 |
if (Check) |
0 |
6179 |
if (Check) |
0 |
| 6180 |
return &I; |
0 |
6180 |
return &I; |
0 |
| 6181 |
|
--- |
6181 |
|
--- |
| 6182 |
Instruction *CloneI = I.clone(); |
0 |
6182 |
Instruction *CloneI = I.clone(); |
0 |
| 6183 |
// TODO: Try to salvage debug information here. |
--- |
6183 |
// TODO: Try to salvage debug information here. |
--- |
| 6184 |
CloneI->setDebugLoc(DebugLoc()); |
0 |
6184 |
CloneI->setDebugLoc(DebugLoc()); |
0 |
| 6185 |
VMap[&I] = CloneI; |
0 |
6185 |
VMap[&I] = CloneI; |
0 |
| 6186 |
CloneI->insertBefore(CtxI); |
0 |
6186 |
CloneI->insertBefore(CtxI); |
0 |
| 6187 |
RemapInstruction(CloneI, VMap); |
0 |
6187 |
RemapInstruction(CloneI, VMap); |
0 |
| 6188 |
return CloneI; |
0 |
6188 |
return CloneI; |
0 |
| 6189 |
} |
--- |
6189 |
} |
--- |
| 6190 |
|
--- |
6190 |
|
--- |
| 6191 |
/// Reproduce \p V with type \p Ty or return nullptr if that is not posisble. |
--- |
6191 |
/// Reproduce \p V with type \p Ty or return nullptr if that is not posisble. |
--- |
| 6192 |
/// If \p Check is true we will only verify such an operation would suceed and |
--- |
6192 |
/// If \p Check is true we will only verify such an operation would suceed and |
--- |
| 6193 |
/// return a non-nullptr value if that is the case. No IR is generated or |
--- |
6193 |
/// return a non-nullptr value if that is the case. No IR is generated or |
--- |
| 6194 |
/// modified. |
--- |
6194 |
/// modified. |
--- |
| 6195 |
static Value *reproduceValue(Attributor &A, |
0 |
6195 |
static Value *reproduceValue(Attributor &A, |
0 |
| 6196 |
const AbstractAttribute &QueryingAA, Value &V, |
--- |
6196 |
const AbstractAttribute &QueryingAA, Value &V, |
--- |
| 6197 |
Type &Ty, Instruction *CtxI, bool Check, |
--- |
6197 |
Type &Ty, Instruction *CtxI, bool Check, |
--- |
| 6198 |
ValueToValueMapTy &VMap) { |
--- |
6198 |
ValueToValueMapTy &VMap) { |
--- |
| 6199 |
if (const auto &NewV = VMap.lookup(&V)) |
0 |
6199 |
if (const auto &NewV = VMap.lookup(&V)) |
0 |
| 6200 |
return NewV; |
0 |
6200 |
return NewV; |
0 |
| 6201 |
bool UsedAssumedInformation = false; |
0 |
6201 |
bool UsedAssumedInformation = false; |
0 |
| 6202 |
std::optional SimpleV = A.getAssumedSimplified( |
0 |
6202 |
std::optional SimpleV = A.getAssumedSimplified( |
0 |
| 6203 |
V, QueryingAA, UsedAssumedInformation, AA::Interprocedural); |
--- |
6203 |
V, QueryingAA, UsedAssumedInformation, AA::Interprocedural); |
--- |
| 6204 |
if (!SimpleV.has_value()) |
0 |
6204 |
if (!SimpleV.has_value()) |
0 |
| 6205 |
return PoisonValue::get(&Ty); |
0 |
6205 |
return PoisonValue::get(&Ty); |
0 |
| 6206 |
Value *EffectiveV = &V; |
0 |
6206 |
Value *EffectiveV = &V; |
0 |
| 6207 |
if (*SimpleV) |
0 |
6207 |
if (*SimpleV) |
0 |
| 6208 |
EffectiveV = *SimpleV; |
0 |
6208 |
EffectiveV = *SimpleV; |
0 |
| 6209 |
if (auto *C = dyn_cast(EffectiveV)) |
0 |
6209 |
if (auto *C = dyn_cast(EffectiveV)) |
0 |
| 6210 |
return C; |
0 |
6210 |
return C; |
0 |
| 6211 |
if (CtxI && AA::isValidAtPosition(AA::ValueAndContext(*EffectiveV, *CtxI), |
0 |
6211 |
if (CtxI && AA::isValidAtPosition(AA::ValueAndContext(*EffectiveV, *CtxI), |
0 |
| 6212 |
A.getInfoCache())) |
--- |
6212 |
A.getInfoCache())) |
--- |
| 6213 |
return ensureType(A, *EffectiveV, Ty, CtxI, Check); |
0 |
6213 |
return ensureType(A, *EffectiveV, Ty, CtxI, Check); |
0 |
| 6214 |
if (auto *I = dyn_cast(EffectiveV)) |
0 |
6214 |
if (auto *I = dyn_cast(EffectiveV)) |
0 |
| 6215 |
if (Value *NewV = reproduceInst(A, QueryingAA, *I, Ty, CtxI, Check, VMap)) |
0 |
6215 |
if (Value *NewV = reproduceInst(A, QueryingAA, *I, Ty, CtxI, Check, VMap)) |
0 |
| 6216 |
return ensureType(A, *NewV, Ty, CtxI, Check); |
0 |
6216 |
return ensureType(A, *NewV, Ty, CtxI, Check); |
0 |
| 6217 |
return nullptr; |
0 |
6217 |
return nullptr; |
0 |
| 6218 |
} |
--- |
6218 |
} |
--- |
| 6219 |
|
--- |
6219 |
|
--- |
| 6220 |
/// Return a value we can use as replacement for the associated one, or |
--- |
6220 |
/// Return a value we can use as replacement for the associated one, or |
--- |
| 6221 |
/// nullptr if we don't have one that makes sense. |
--- |
6221 |
/// nullptr if we don't have one that makes sense. |
--- |
| 6222 |
Value *manifestReplacementValue(Attributor &A, Instruction *CtxI) const { |
0 |
6222 |
Value *manifestReplacementValue(Attributor &A, Instruction *CtxI) const { |
0 |
| 6223 |
Value *NewV = SimplifiedAssociatedValue |
--- |
6223 |
Value *NewV = SimplifiedAssociatedValue |
--- |
| 6224 |
? *SimplifiedAssociatedValue |
0 |
6224 |
? *SimplifiedAssociatedValue |
0 |
| 6225 |
: UndefValue::get(getAssociatedType()); |
0 |
6225 |
: UndefValue::get(getAssociatedType()); |
0 |
| 6226 |
if (NewV && NewV != &getAssociatedValue()) { |
0 |
6226 |
if (NewV && NewV != &getAssociatedValue()) { |
0 |
| 6227 |
ValueToValueMapTy VMap; |
0 |
6227 |
ValueToValueMapTy VMap; |
0 |
| 6228 |
// First verify we can reprduce the value with the required type at the |
--- |
6228 |
// First verify we can reprduce the value with the required type at the |
--- |
| 6229 |
// context location before we actually start modifying the IR. |
--- |
6229 |
// context location before we actually start modifying the IR. |
--- |
| 6230 |
if (reproduceValue(A, *this, *NewV, *getAssociatedType(), CtxI, |
0 |
6230 |
if (reproduceValue(A, *this, *NewV, *getAssociatedType(), CtxI, |
0 |
| 6231 |
/* CheckOnly */ true, VMap)) |
--- |
6231 |
/* CheckOnly */ true, VMap)) |
--- |
| 6232 |
return reproduceValue(A, *this, *NewV, *getAssociatedType(), CtxI, |
0 |
6232 |
return reproduceValue(A, *this, *NewV, *getAssociatedType(), CtxI, |
0 |
| 6233 |
/* CheckOnly */ false, VMap); |
0 |
6233 |
/* CheckOnly */ false, VMap); |
0 |
| 6234 |
} |
0 |
6234 |
} |
0 |
| 6235 |
return nullptr; |
0 |
6235 |
return nullptr; |
0 |
| 6236 |
} |
--- |
6236 |
} |
--- |
| 6237 |
|
--- |
6237 |
|
--- |
| 6238 |
/// Helper function for querying AAValueSimplify and updating candidate. |
--- |
6238 |
/// Helper function for querying AAValueSimplify and updating candidate. |
--- |
| 6239 |
/// \param IRP The value position we are trying to unify with SimplifiedValue |
--- |
6239 |
/// \param IRP The value position we are trying to unify with SimplifiedValue |
--- |
| 6240 |
bool checkAndUpdate(Attributor &A, const AbstractAttribute &QueryingAA, |
0 |
6240 |
bool checkAndUpdate(Attributor &A, const AbstractAttribute &QueryingAA, |
0 |
| 6241 |
const IRPosition &IRP, bool Simplify = true) { |
--- |
6241 |
const IRPosition &IRP, bool Simplify = true) { |
--- |
| 6242 |
bool UsedAssumedInformation = false; |
0 |
6242 |
bool UsedAssumedInformation = false; |
0 |
| 6243 |
std::optional QueryingValueSimplified = &IRP.getAssociatedValue(); |
0 |
6243 |
std::optional QueryingValueSimplified = &IRP.getAssociatedValue(); |
0 |
| 6244 |
if (Simplify) |
0 |
6244 |
if (Simplify) |
0 |
| 6245 |
QueryingValueSimplified = A.getAssumedSimplified( |
0 |
6245 |
QueryingValueSimplified = A.getAssumedSimplified( |
0 |
| 6246 |
IRP, QueryingAA, UsedAssumedInformation, AA::Interprocedural); |
--- |
6246 |
IRP, QueryingAA, UsedAssumedInformation, AA::Interprocedural); |
--- |
| 6247 |
return unionAssumed(QueryingValueSimplified); |
0 |
6247 |
return unionAssumed(QueryingValueSimplified); |
0 |
| 6248 |
} |
--- |
6248 |
} |
--- |
| 6249 |
|
--- |
6249 |
|
--- |
| 6250 |
/// Returns a candidate is found or not |
--- |
6250 |
/// Returns a candidate is found or not |
--- |
| 6251 |
template bool askSimplifiedValueFor(Attributor &A) { |
0 |
6251 |
template bool askSimplifiedValueFor(Attributor &A) { |
0 |
| 6252 |
if (!getAssociatedValue().getType()->isIntegerTy()) |
0 |
6252 |
if (!getAssociatedValue().getType()->isIntegerTy()) |
0 |
| 6253 |
return false; |
0 |
6253 |
return false; |
0 |
| 6254 |
|
--- |
6254 |
|
--- |
| 6255 |
// This will also pass the call base context. |
--- |
6255 |
// This will also pass the call base context. |
--- |
| 6256 |
const auto *AA = |
--- |
6256 |
const auto *AA = |
--- |
| 6257 |
A.getAAFor(*this, getIRPosition(), DepClassTy::NONE); |
0 |
6257 |
A.getAAFor(*this, getIRPosition(), DepClassTy::NONE); |
0 |
| 6258 |
if (!AA) |
0 |
6258 |
if (!AA) |
0 |
| 6259 |
return false; |
0 |
6259 |
return false; |
0 |
| 6260 |
|
--- |
6260 |
|
--- |
| 6261 |
std::optional COpt = AA->getAssumedConstant(A); |
0 |
6261 |
std::optional COpt = AA->getAssumedConstant(A); |
0 |
| 6262 |
|
--- |
6262 |
|
--- |
| 6263 |
if (!COpt) { |
0 |
6263 |
if (!COpt) { |
0 |
| 6264 |
SimplifiedAssociatedValue = std::nullopt; |
0 |
6264 |
SimplifiedAssociatedValue = std::nullopt; |
0 |
| 6265 |
A.recordDependence(*AA, *this, DepClassTy::OPTIONAL); |
0 |
6265 |
A.recordDependence(*AA, *this, DepClassTy::OPTIONAL); |
0 |
| 6266 |
return true; |
0 |
6266 |
return true; |
0 |
| 6267 |
} |
--- |
6267 |
} |
--- |
| 6268 |
if (auto *C = *COpt) { |
0 |
6268 |
if (auto *C = *COpt) { |
0 |
| 6269 |
SimplifiedAssociatedValue = C; |
0 |
6269 |
SimplifiedAssociatedValue = C; |
0 |
| 6270 |
A.recordDependence(*AA, *this, DepClassTy::OPTIONAL); |
0 |
6270 |
A.recordDependence(*AA, *this, DepClassTy::OPTIONAL); |
0 |
| 6271 |
return true; |
0 |
6271 |
return true; |
0 |
| 6272 |
} |
--- |
6272 |
} |
--- |
| 6273 |
return false; |
0 |
6273 |
return false; |
0 |
| 6274 |
} |
--- |
6274 |
} |
--- |
| 6275 |
|
--- |
6275 |
|
--- |
| 6276 |
bool askSimplifiedValueForOtherAAs(Attributor &A) { |
0 |
6276 |
bool askSimplifiedValueForOtherAAs(Attributor &A) { |
0 |
| 6277 |
if (askSimplifiedValueFor(A)) |
0 |
6277 |
if (askSimplifiedValueFor(A)) |
0 |
| 6278 |
return true; |
0 |
6278 |
return true; |
0 |
| 6279 |
if (askSimplifiedValueFor(A)) |
0 |
6279 |
if (askSimplifiedValueFor(A)) |
0 |
| 6280 |
return true; |
0 |
6280 |
return true; |
0 |
| 6281 |
return false; |
0 |
6281 |
return false; |
0 |
| 6282 |
} |
--- |
6282 |
} |
--- |
| 6283 |
|
--- |
6283 |
|
--- |
| 6284 |
/// See AbstractAttribute::manifest(...). |
--- |
6284 |
/// See AbstractAttribute::manifest(...). |
--- |
| 6285 |
ChangeStatus manifest(Attributor &A) override { |
0 |
6285 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 6286 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
6286 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 6287 |
for (auto &U : getAssociatedValue().uses()) { |
0 |
6287 |
for (auto &U : getAssociatedValue().uses()) { |
0 |
| 6288 |
// Check if we need to adjust the insertion point to make sure the IR is |
--- |
6288 |
// Check if we need to adjust the insertion point to make sure the IR is |
--- |
| 6289 |
// valid. |
--- |
6289 |
// valid. |
--- |
| 6290 |
Instruction *IP = dyn_cast(U.getUser()); |
0 |
6290 |
Instruction *IP = dyn_cast(U.getUser()); |
0 |
| 6291 |
if (auto *PHI = dyn_cast_or_null(IP)) |
0 |
6291 |
if (auto *PHI = dyn_cast_or_null(IP)) |
0 |
| 6292 |
IP = PHI->getIncomingBlock(U)->getTerminator(); |
0 |
6292 |
IP = PHI->getIncomingBlock(U)->getTerminator(); |
0 |
| 6293 |
if (auto *NewV = manifestReplacementValue(A, IP)) { |
0 |
6293 |
if (auto *NewV = manifestReplacementValue(A, IP)) { |
0 |
| 6294 |
LLVM_DEBUG(dbgs() << "[ValueSimplify] " << getAssociatedValue() |
0 |
6294 |
LLVM_DEBUG(dbgs() << "[ValueSimplify] " << getAssociatedValue() |
0 |
| 6295 |
<< " -> " << *NewV << " :: " << *this << "\n"); |
--- |
6295 |
<< " -> " << *NewV << " :: " << *this << "\n"); |
--- |
| 6296 |
if (A.changeUseAfterManifest(U, *NewV)) |
0 |
6296 |
if (A.changeUseAfterManifest(U, *NewV)) |
0 |
| 6297 |
Changed = ChangeStatus::CHANGED; |
0 |
6297 |
Changed = ChangeStatus::CHANGED; |
0 |
| 6298 |
} |
--- |
6298 |
} |
--- |
| 6299 |
} |
--- |
6299 |
} |
--- |
| 6300 |
|
--- |
6300 |
|
--- |
| 6301 |
return Changed | AAValueSimplify::manifest(A); |
0 |
6301 |
return Changed | AAValueSimplify::manifest(A); |
0 |
| 6302 |
} |
--- |
6302 |
} |
--- |
| 6303 |
|
--- |
6303 |
|
--- |
| 6304 |
/// See AbstractState::indicatePessimisticFixpoint(...). |
--- |
6304 |
/// See AbstractState::indicatePessimisticFixpoint(...). |
--- |
| 6305 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
6305 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
| 6306 |
SimplifiedAssociatedValue = &getAssociatedValue(); |
0 |
6306 |
SimplifiedAssociatedValue = &getAssociatedValue(); |
0 |
| 6307 |
return AAValueSimplify::indicatePessimisticFixpoint(); |
0 |
6307 |
return AAValueSimplify::indicatePessimisticFixpoint(); |
0 |
| 6308 |
} |
--- |
6308 |
} |
--- |
| 6309 |
}; |
--- |
6309 |
}; |
--- |
| 6310 |
|
--- |
6310 |
|
--- |
| 6311 |
struct AAValueSimplifyArgument final : AAValueSimplifyImpl { |
--- |
6311 |
struct AAValueSimplifyArgument final : AAValueSimplifyImpl { |
--- |
| 6312 |
AAValueSimplifyArgument(const IRPosition &IRP, Attributor &A) |
0 |
6312 |
AAValueSimplifyArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 6313 |
: AAValueSimplifyImpl(IRP, A) {} |
0 |
6313 |
: AAValueSimplifyImpl(IRP, A) {} |
0 |
| 6314 |
|
--- |
6314 |
|
--- |
| 6315 |
void initialize(Attributor &A) override { |
0 |
6315 |
void initialize(Attributor &A) override { |
0 |
| 6316 |
AAValueSimplifyImpl::initialize(A); |
0 |
6316 |
AAValueSimplifyImpl::initialize(A); |
0 |
| 6317 |
if (A.hasAttr(getIRPosition(), |
0 |
6317 |
if (A.hasAttr(getIRPosition(), |
0 |
| 6318 |
{Attribute::InAlloca, Attribute::Preallocated, |
--- |
6318 |
{Attribute::InAlloca, Attribute::Preallocated, |
--- |
| 6319 |
Attribute::StructRet, Attribute::Nest, Attribute::ByVal}, |
--- |
6319 |
Attribute::StructRet, Attribute::Nest, Attribute::ByVal}, |
--- |
| 6320 |
/* IgnoreSubsumingPositions */ true)) |
--- |
6320 |
/* IgnoreSubsumingPositions */ true)) |
--- |
| 6321 |
indicatePessimisticFixpoint(); |
0 |
6321 |
indicatePessimisticFixpoint(); |
0 |
| 6322 |
} |
0 |
6322 |
} |
0 |
| 6323 |
|
--- |
6323 |
|
--- |
| 6324 |
/// See AbstractAttribute::updateImpl(...). |
--- |
6324 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 6325 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
6325 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 6326 |
// Byval is only replacable if it is readonly otherwise we would write into |
--- |
6326 |
// Byval is only replacable if it is readonly otherwise we would write into |
--- |
| 6327 |
// the replaced value and not the copy that byval creates implicitly. |
--- |
6327 |
// the replaced value and not the copy that byval creates implicitly. |
--- |
| 6328 |
Argument *Arg = getAssociatedArgument(); |
0 |
6328 |
Argument *Arg = getAssociatedArgument(); |
0 |
| 6329 |
if (Arg->hasByValAttr()) { |
0 |
6329 |
if (Arg->hasByValAttr()) { |
0 |
| 6330 |
// TODO: We probably need to verify synchronization is not an issue, e.g., |
--- |
6330 |
// TODO: We probably need to verify synchronization is not an issue, e.g., |
--- |
| 6331 |
// there is no race by not copying a constant byval. |
--- |
6331 |
// there is no race by not copying a constant byval. |
--- |
| 6332 |
bool IsKnown; |
--- |
6332 |
bool IsKnown; |
--- |
| 6333 |
if (!AA::isAssumedReadOnly(A, getIRPosition(), *this, IsKnown)) |
0 |
6333 |
if (!AA::isAssumedReadOnly(A, getIRPosition(), *this, IsKnown)) |
0 |
| 6334 |
return indicatePessimisticFixpoint(); |
0 |
6334 |
return indicatePessimisticFixpoint(); |
0 |
| 6335 |
} |
--- |
6335 |
} |
--- |
| 6336 |
|
--- |
6336 |
|
--- |
| 6337 |
auto Before = SimplifiedAssociatedValue; |
0 |
6337 |
auto Before = SimplifiedAssociatedValue; |
0 |
| 6338 |
|
--- |
6338 |
|
--- |
| 6339 |
auto PredForCallSite = [&](AbstractCallSite ACS) { |
0 |
6339 |
auto PredForCallSite = [&](AbstractCallSite ACS) { |
0 |
| 6340 |
const IRPosition &ACSArgPos = |
--- |
6340 |
const IRPosition &ACSArgPos = |
--- |
| 6341 |
IRPosition::callsite_argument(ACS, getCallSiteArgNo()); |
0 |
6341 |
IRPosition::callsite_argument(ACS, getCallSiteArgNo()); |
0 |
| 6342 |
// Check if a coresponding argument was found or if it is on not |
--- |
6342 |
// Check if a coresponding argument was found or if it is on not |
--- |
| 6343 |
// associated (which can happen for callback calls). |
--- |
6343 |
// associated (which can happen for callback calls). |
--- |
| 6344 |
if (ACSArgPos.getPositionKind() == IRPosition::IRP_INVALID) |
0 |
6344 |
if (ACSArgPos.getPositionKind() == IRPosition::IRP_INVALID) |
0 |
| 6345 |
return false; |
0 |
6345 |
return false; |
0 |
| 6346 |
|
--- |
6346 |
|
--- |
| 6347 |
// Simplify the argument operand explicitly and check if the result is |
--- |
6347 |
// Simplify the argument operand explicitly and check if the result is |
--- |
| 6348 |
// valid in the current scope. This avoids refering to simplified values |
--- |
6348 |
// valid in the current scope. This avoids refering to simplified values |
--- |
| 6349 |
// in other functions, e.g., we don't want to say a an argument in a |
--- |
6349 |
// in other functions, e.g., we don't want to say a an argument in a |
--- |
| 6350 |
// static function is actually an argument in a different function. |
--- |
6350 |
// static function is actually an argument in a different function. |
--- |
| 6351 |
bool UsedAssumedInformation = false; |
0 |
6351 |
bool UsedAssumedInformation = false; |
0 |
| 6352 |
std::optional SimpleArgOp = |
--- |
6352 |
std::optional SimpleArgOp = |
--- |
| 6353 |
A.getAssumedConstant(ACSArgPos, *this, UsedAssumedInformation); |
0 |
6353 |
A.getAssumedConstant(ACSArgPos, *this, UsedAssumedInformation); |
0 |
| 6354 |
if (!SimpleArgOp) |
0 |
6354 |
if (!SimpleArgOp) |
0 |
| 6355 |
return true; |
0 |
6355 |
return true; |
0 |
| 6356 |
if (!*SimpleArgOp) |
0 |
6356 |
if (!*SimpleArgOp) |
0 |
| 6357 |
return false; |
0 |
6357 |
return false; |
0 |
| 6358 |
if (!AA::isDynamicallyUnique(A, *this, **SimpleArgOp)) |
0 |
6358 |
if (!AA::isDynamicallyUnique(A, *this, **SimpleArgOp)) |
0 |
| 6359 |
return false; |
0 |
6359 |
return false; |
0 |
| 6360 |
return unionAssumed(*SimpleArgOp); |
0 |
6360 |
return unionAssumed(*SimpleArgOp); |
0 |
| 6361 |
}; |
0 |
6361 |
}; |
0 |
| 6362 |
|
--- |
6362 |
|
--- |
| 6363 |
// Generate a answer specific to a call site context. |
--- |
6363 |
// Generate a answer specific to a call site context. |
--- |
| 6364 |
bool Success; |
--- |
6364 |
bool Success; |
--- |
| 6365 |
bool UsedAssumedInformation = false; |
0 |
6365 |
bool UsedAssumedInformation = false; |
0 |
| 6366 |
if (hasCallBaseContext() && |
0 |
6366 |
if (hasCallBaseContext() && |
0 |
| 6367 |
getCallBaseContext()->getCalledOperand() == Arg->getParent()) |
0 |
6367 |
getCallBaseContext()->getCalledOperand() == Arg->getParent()) |
0 |
| 6368 |
Success = PredForCallSite( |
0 |
6368 |
Success = PredForCallSite( |
0 |
| 6369 |
AbstractCallSite(&getCallBaseContext()->getCalledOperandUse())); |
0 |
6369 |
AbstractCallSite(&getCallBaseContext()->getCalledOperandUse())); |
0 |
| 6370 |
else |
--- |
6370 |
else |
--- |
| 6371 |
Success = A.checkForAllCallSites(PredForCallSite, *this, true, |
0 |
6371 |
Success = A.checkForAllCallSites(PredForCallSite, *this, true, |
0 |
| 6372 |
UsedAssumedInformation); |
--- |
6372 |
UsedAssumedInformation); |
--- |
| 6373 |
|
--- |
6373 |
|
--- |
| 6374 |
if (!Success) |
0 |
6374 |
if (!Success) |
0 |
| 6375 |
if (!askSimplifiedValueForOtherAAs(A)) |
0 |
6375 |
if (!askSimplifiedValueForOtherAAs(A)) |
0 |
| 6376 |
return indicatePessimisticFixpoint(); |
0 |
6376 |
return indicatePessimisticFixpoint(); |
0 |
| 6377 |
|
--- |
6377 |
|
--- |
| 6378 |
// If a candidate was found in this update, return CHANGED. |
--- |
6378 |
// If a candidate was found in this update, return CHANGED. |
--- |
| 6379 |
return Before == SimplifiedAssociatedValue ? ChangeStatus::UNCHANGED |
0 |
6379 |
return Before == SimplifiedAssociatedValue ? ChangeStatus::UNCHANGED |
0 |
| 6380 |
: ChangeStatus ::CHANGED; |
0 |
6380 |
: ChangeStatus ::CHANGED; |
0 |
| 6381 |
} |
--- |
6381 |
} |
--- |
| 6382 |
|
--- |
6382 |
|
--- |
| 6383 |
/// See AbstractAttribute::trackStatistics() |
--- |
6383 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 6384 |
void trackStatistics() const override { |
0 |
6384 |
void trackStatistics() const override { |
0 |
| 6385 |
STATS_DECLTRACK_ARG_ATTR(value_simplify) |
0 |
6385 |
STATS_DECLTRACK_ARG_ATTR(value_simplify) |
0 |
| 6386 |
} |
0 |
6386 |
} |
0 |
| 6387 |
}; |
--- |
6387 |
}; |
--- |
| 6388 |
|
--- |
6388 |
|
--- |
| 6389 |
struct AAValueSimplifyReturned : AAValueSimplifyImpl { |
--- |
6389 |
struct AAValueSimplifyReturned : AAValueSimplifyImpl { |
--- |
| 6390 |
AAValueSimplifyReturned(const IRPosition &IRP, Attributor &A) |
0 |
6390 |
AAValueSimplifyReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 6391 |
: AAValueSimplifyImpl(IRP, A) {} |
0 |
6391 |
: AAValueSimplifyImpl(IRP, A) {} |
0 |
| 6392 |
|
--- |
6392 |
|
--- |
| 6393 |
/// See AAValueSimplify::getAssumedSimplifiedValue() |
--- |
6393 |
/// See AAValueSimplify::getAssumedSimplifiedValue() |
--- |
| 6394 |
std::optional |
--- |
6394 |
std::optional |
--- |
| 6395 |
getAssumedSimplifiedValue(Attributor &A) const override { |
0 |
6395 |
getAssumedSimplifiedValue(Attributor &A) const override { |
0 |
| 6396 |
if (!isValidState()) |
0 |
6396 |
if (!isValidState()) |
0 |
| 6397 |
return nullptr; |
0 |
6397 |
return nullptr; |
0 |
| 6398 |
return SimplifiedAssociatedValue; |
0 |
6398 |
return SimplifiedAssociatedValue; |
0 |
| 6399 |
} |
--- |
6399 |
} |
--- |
| 6400 |
|
--- |
6400 |
|
--- |
| 6401 |
/// See AbstractAttribute::updateImpl(...). |
--- |
6401 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 6402 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
6402 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 6403 |
auto Before = SimplifiedAssociatedValue; |
0 |
6403 |
auto Before = SimplifiedAssociatedValue; |
0 |
| 6404 |
|
--- |
6404 |
|
--- |
| 6405 |
auto ReturnInstCB = [&](Instruction &I) { |
0 |
6405 |
auto ReturnInstCB = [&](Instruction &I) { |
0 |
| 6406 |
auto &RI = cast(I); |
0 |
6406 |
auto &RI = cast(I); |
0 |
| 6407 |
return checkAndUpdate( |
0 |
6407 |
return checkAndUpdate( |
0 |
| 6408 |
A, *this, |
0 |
6408 |
A, *this, |
0 |
| 6409 |
IRPosition::value(*RI.getReturnValue(), getCallBaseContext())); |
0 |
6409 |
IRPosition::value(*RI.getReturnValue(), getCallBaseContext())); |
0 |
| 6410 |
}; |
0 |
6410 |
}; |
0 |
| 6411 |
|
--- |
6411 |
|
--- |
| 6412 |
bool UsedAssumedInformation = false; |
0 |
6412 |
bool UsedAssumedInformation = false; |
0 |
| 6413 |
if (!A.checkForAllInstructions(ReturnInstCB, *this, {Instruction::Ret}, |
0 |
6413 |
if (!A.checkForAllInstructions(ReturnInstCB, *this, {Instruction::Ret}, |
0 |
| 6414 |
UsedAssumedInformation)) |
--- |
6414 |
UsedAssumedInformation)) |
--- |
| 6415 |
if (!askSimplifiedValueForOtherAAs(A)) |
0 |
6415 |
if (!askSimplifiedValueForOtherAAs(A)) |
0 |
| 6416 |
return indicatePessimisticFixpoint(); |
0 |
6416 |
return indicatePessimisticFixpoint(); |
0 |
| 6417 |
|
--- |
6417 |
|
--- |
| 6418 |
// If a candidate was found in this update, return CHANGED. |
--- |
6418 |
// If a candidate was found in this update, return CHANGED. |
--- |
| 6419 |
return Before == SimplifiedAssociatedValue ? ChangeStatus::UNCHANGED |
0 |
6419 |
return Before == SimplifiedAssociatedValue ? ChangeStatus::UNCHANGED |
0 |
| 6420 |
: ChangeStatus ::CHANGED; |
0 |
6420 |
: ChangeStatus ::CHANGED; |
0 |
| 6421 |
} |
--- |
6421 |
} |
--- |
| 6422 |
|
--- |
6422 |
|
--- |
| 6423 |
ChangeStatus manifest(Attributor &A) override { |
0 |
6423 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 6424 |
// We queried AAValueSimplify for the returned values so they will be |
--- |
6424 |
// We queried AAValueSimplify for the returned values so they will be |
--- |
| 6425 |
// replaced if a simplified form was found. Nothing to do here. |
--- |
6425 |
// replaced if a simplified form was found. Nothing to do here. |
--- |
| 6426 |
return ChangeStatus::UNCHANGED; |
0 |
6426 |
return ChangeStatus::UNCHANGED; |
0 |
| 6427 |
} |
--- |
6427 |
} |
--- |
| 6428 |
|
--- |
6428 |
|
--- |
| 6429 |
/// See AbstractAttribute::trackStatistics() |
--- |
6429 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 6430 |
void trackStatistics() const override { |
0 |
6430 |
void trackStatistics() const override { |
0 |
| 6431 |
STATS_DECLTRACK_FNRET_ATTR(value_simplify) |
0 |
6431 |
STATS_DECLTRACK_FNRET_ATTR(value_simplify) |
0 |
| 6432 |
} |
0 |
6432 |
} |
0 |
| 6433 |
}; |
--- |
6433 |
}; |
--- |
| 6434 |
|
--- |
6434 |
|
--- |
| 6435 |
struct AAValueSimplifyFloating : AAValueSimplifyImpl { |
--- |
6435 |
struct AAValueSimplifyFloating : AAValueSimplifyImpl { |
--- |
| 6436 |
AAValueSimplifyFloating(const IRPosition &IRP, Attributor &A) |
0 |
6436 |
AAValueSimplifyFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 6437 |
: AAValueSimplifyImpl(IRP, A) {} |
0 |
6437 |
: AAValueSimplifyImpl(IRP, A) {} |
0 |
| 6438 |
|
--- |
6438 |
|
--- |
| 6439 |
/// See AbstractAttribute::initialize(...). |
--- |
6439 |
/// See AbstractAttribute::initialize(...). |
--- |
| 6440 |
void initialize(Attributor &A) override { |
0 |
6440 |
void initialize(Attributor &A) override { |
0 |
| 6441 |
AAValueSimplifyImpl::initialize(A); |
0 |
6441 |
AAValueSimplifyImpl::initialize(A); |
0 |
| 6442 |
Value &V = getAnchorValue(); |
0 |
6442 |
Value &V = getAnchorValue(); |
0 |
| 6443 |
|
--- |
6443 |
|
--- |
| 6444 |
// TODO: add other stuffs |
--- |
6444 |
// TODO: add other stuffs |
--- |
| 6445 |
if (isa(V)) |
0 |
6445 |
if (isa(V)) |
0 |
| 6446 |
indicatePessimisticFixpoint(); |
0 |
6446 |
indicatePessimisticFixpoint(); |
0 |
| 6447 |
} |
0 |
6447 |
} |
0 |
| 6448 |
|
--- |
6448 |
|
--- |
| 6449 |
/// See AbstractAttribute::updateImpl(...). |
--- |
6449 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 6450 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
6450 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 6451 |
auto Before = SimplifiedAssociatedValue; |
0 |
6451 |
auto Before = SimplifiedAssociatedValue; |
0 |
| 6452 |
if (!askSimplifiedValueForOtherAAs(A)) |
0 |
6452 |
if (!askSimplifiedValueForOtherAAs(A)) |
0 |
| 6453 |
return indicatePessimisticFixpoint(); |
0 |
6453 |
return indicatePessimisticFixpoint(); |
0 |
| 6454 |
|
--- |
6454 |
|
--- |
| 6455 |
// If a candidate was found in this update, return CHANGED. |
--- |
6455 |
// If a candidate was found in this update, return CHANGED. |
--- |
| 6456 |
return Before == SimplifiedAssociatedValue ? ChangeStatus::UNCHANGED |
0 |
6456 |
return Before == SimplifiedAssociatedValue ? ChangeStatus::UNCHANGED |
0 |
| 6457 |
: ChangeStatus ::CHANGED; |
0 |
6457 |
: ChangeStatus ::CHANGED; |
0 |
| 6458 |
} |
--- |
6458 |
} |
--- |
| 6459 |
|
--- |
6459 |
|
--- |
| 6460 |
/// See AbstractAttribute::trackStatistics() |
--- |
6460 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 6461 |
void trackStatistics() const override { |
0 |
6461 |
void trackStatistics() const override { |
0 |
| 6462 |
STATS_DECLTRACK_FLOATING_ATTR(value_simplify) |
0 |
6462 |
STATS_DECLTRACK_FLOATING_ATTR(value_simplify) |
0 |
| 6463 |
} |
0 |
6463 |
} |
0 |
| 6464 |
}; |
--- |
6464 |
}; |
--- |
| 6465 |
|
--- |
6465 |
|
--- |
| 6466 |
struct AAValueSimplifyFunction : AAValueSimplifyImpl { |
--- |
6466 |
struct AAValueSimplifyFunction : AAValueSimplifyImpl { |
--- |
| 6467 |
AAValueSimplifyFunction(const IRPosition &IRP, Attributor &A) |
0 |
6467 |
AAValueSimplifyFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 6468 |
: AAValueSimplifyImpl(IRP, A) {} |
0 |
6468 |
: AAValueSimplifyImpl(IRP, A) {} |
0 |
| 6469 |
|
--- |
6469 |
|
--- |
| 6470 |
/// See AbstractAttribute::initialize(...). |
--- |
6470 |
/// See AbstractAttribute::initialize(...). |
--- |
| 6471 |
void initialize(Attributor &A) override { |
0 |
6471 |
void initialize(Attributor &A) override { |
0 |
| 6472 |
SimplifiedAssociatedValue = nullptr; |
0 |
6472 |
SimplifiedAssociatedValue = nullptr; |
0 |
| 6473 |
indicateOptimisticFixpoint(); |
0 |
6473 |
indicateOptimisticFixpoint(); |
0 |
| 6474 |
} |
0 |
6474 |
} |
0 |
| 6475 |
/// See AbstractAttribute::initialize(...). |
--- |
6475 |
/// See AbstractAttribute::initialize(...). |
--- |
| 6476 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
6476 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 6477 |
llvm_unreachable( |
0 |
6477 |
llvm_unreachable( |
0 |
| 6478 |
"AAValueSimplify(Function|CallSite)::updateImpl will not be called"); |
--- |
6478 |
"AAValueSimplify(Function|CallSite)::updateImpl will not be called"); |
--- |
| 6479 |
} |
--- |
6479 |
} |
--- |
| 6480 |
/// See AbstractAttribute::trackStatistics() |
--- |
6480 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 6481 |
void trackStatistics() const override { |
0 |
6481 |
void trackStatistics() const override { |
0 |
| 6482 |
STATS_DECLTRACK_FN_ATTR(value_simplify) |
0 |
6482 |
STATS_DECLTRACK_FN_ATTR(value_simplify) |
0 |
| 6483 |
} |
0 |
6483 |
} |
0 |
| 6484 |
}; |
--- |
6484 |
}; |
--- |
| 6485 |
|
--- |
6485 |
|
--- |
| 6486 |
struct AAValueSimplifyCallSite : AAValueSimplifyFunction { |
--- |
6486 |
struct AAValueSimplifyCallSite : AAValueSimplifyFunction { |
--- |
| 6487 |
AAValueSimplifyCallSite(const IRPosition &IRP, Attributor &A) |
0 |
6487 |
AAValueSimplifyCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 6488 |
: AAValueSimplifyFunction(IRP, A) {} |
0 |
6488 |
: AAValueSimplifyFunction(IRP, A) {} |
0 |
| 6489 |
/// See AbstractAttribute::trackStatistics() |
--- |
6489 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 6490 |
void trackStatistics() const override { |
0 |
6490 |
void trackStatistics() const override { |
0 |
| 6491 |
STATS_DECLTRACK_CS_ATTR(value_simplify) |
0 |
6491 |
STATS_DECLTRACK_CS_ATTR(value_simplify) |
0 |
| 6492 |
} |
0 |
6492 |
} |
0 |
| 6493 |
}; |
--- |
6493 |
}; |
--- |
| 6494 |
|
--- |
6494 |
|
--- |
| 6495 |
struct AAValueSimplifyCallSiteReturned : AAValueSimplifyImpl { |
--- |
6495 |
struct AAValueSimplifyCallSiteReturned : AAValueSimplifyImpl { |
--- |
| 6496 |
AAValueSimplifyCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
6496 |
AAValueSimplifyCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 6497 |
: AAValueSimplifyImpl(IRP, A) {} |
0 |
6497 |
: AAValueSimplifyImpl(IRP, A) {} |
0 |
| 6498 |
|
--- |
6498 |
|
--- |
| 6499 |
void initialize(Attributor &A) override { |
0 |
6499 |
void initialize(Attributor &A) override { |
0 |
| 6500 |
AAValueSimplifyImpl::initialize(A); |
0 |
6500 |
AAValueSimplifyImpl::initialize(A); |
0 |
| 6501 |
Function *Fn = getAssociatedFunction(); |
0 |
6501 |
Function *Fn = getAssociatedFunction(); |
0 |
| 6502 |
assert(Fn && "Did expect an associted function"); |
0 |
6502 |
assert(Fn && "Did expect an associted function"); |
0 |
| 6503 |
for (Argument &Arg : Fn->args()) { |
0 |
6503 |
for (Argument &Arg : Fn->args()) { |
0 |
| 6504 |
if (Arg.hasReturnedAttr()) { |
0 |
6504 |
if (Arg.hasReturnedAttr()) { |
0 |
| 6505 |
auto IRP = IRPosition::callsite_argument(*cast(getCtxI()), |
0 |
6505 |
auto IRP = IRPosition::callsite_argument(*cast(getCtxI()), |
0 |
| 6506 |
Arg.getArgNo()); |
--- |
6506 |
Arg.getArgNo()); |
--- |
| 6507 |
if (IRP.getPositionKind() == IRPosition::IRP_CALL_SITE_ARGUMENT && |
0 |
6507 |
if (IRP.getPositionKind() == IRPosition::IRP_CALL_SITE_ARGUMENT && |
0 |
| 6508 |
checkAndUpdate(A, *this, IRP)) |
0 |
6508 |
checkAndUpdate(A, *this, IRP)) |
0 |
| 6509 |
indicateOptimisticFixpoint(); |
0 |
6509 |
indicateOptimisticFixpoint(); |
0 |
| 6510 |
else |
--- |
6510 |
else |
--- |
| 6511 |
indicatePessimisticFixpoint(); |
0 |
6511 |
indicatePessimisticFixpoint(); |
0 |
| 6512 |
return; |
0 |
6512 |
return; |
0 |
| 6513 |
} |
--- |
6513 |
} |
--- |
| 6514 |
} |
--- |
6514 |
} |
--- |
| 6515 |
} |
--- |
6515 |
} |
--- |
| 6516 |
|
--- |
6516 |
|
--- |
| 6517 |
/// See AbstractAttribute::updateImpl(...). |
--- |
6517 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 6518 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
6518 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 6519 |
return indicatePessimisticFixpoint(); |
0 |
6519 |
return indicatePessimisticFixpoint(); |
0 |
| 6520 |
} |
--- |
6520 |
} |
--- |
| 6521 |
|
--- |
6521 |
|
--- |
| 6522 |
void trackStatistics() const override { |
0 |
6522 |
void trackStatistics() const override { |
0 |
| 6523 |
STATS_DECLTRACK_CSRET_ATTR(value_simplify) |
0 |
6523 |
STATS_DECLTRACK_CSRET_ATTR(value_simplify) |
0 |
| 6524 |
} |
0 |
6524 |
} |
0 |
| 6525 |
}; |
--- |
6525 |
}; |
--- |
| 6526 |
|
--- |
6526 |
|
--- |
| 6527 |
struct AAValueSimplifyCallSiteArgument : AAValueSimplifyFloating { |
--- |
6527 |
struct AAValueSimplifyCallSiteArgument : AAValueSimplifyFloating { |
--- |
| 6528 |
AAValueSimplifyCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
6528 |
AAValueSimplifyCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 6529 |
: AAValueSimplifyFloating(IRP, A) {} |
0 |
6529 |
: AAValueSimplifyFloating(IRP, A) {} |
0 |
| 6530 |
|
--- |
6530 |
|
--- |
| 6531 |
/// See AbstractAttribute::manifest(...). |
--- |
6531 |
/// See AbstractAttribute::manifest(...). |
--- |
| 6532 |
ChangeStatus manifest(Attributor &A) override { |
0 |
6532 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 6533 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
6533 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 6534 |
// TODO: We should avoid simplification duplication to begin with. |
--- |
6534 |
// TODO: We should avoid simplification duplication to begin with. |
--- |
| 6535 |
auto *FloatAA = A.lookupAAFor( |
0 |
6535 |
auto *FloatAA = A.lookupAAFor( |
0 |
| 6536 |
IRPosition::value(getAssociatedValue()), this, DepClassTy::NONE); |
0 |
6536 |
IRPosition::value(getAssociatedValue()), this, DepClassTy::NONE); |
0 |
| 6537 |
if (FloatAA && FloatAA->getState().isValidState()) |
0 |
6537 |
if (FloatAA && FloatAA->getState().isValidState()) |
0 |
| 6538 |
return Changed; |
0 |
6538 |
return Changed; |
0 |
| 6539 |
|
--- |
6539 |
|
--- |
| 6540 |
if (auto *NewV = manifestReplacementValue(A, getCtxI())) { |
0 |
6540 |
if (auto *NewV = manifestReplacementValue(A, getCtxI())) { |
0 |
| 6541 |
Use &U = cast(&getAnchorValue()) |
0 |
6541 |
Use &U = cast(&getAnchorValue()) |
0 |
| 6542 |
->getArgOperandUse(getCallSiteArgNo()); |
0 |
6542 |
->getArgOperandUse(getCallSiteArgNo()); |
0 |
| 6543 |
if (A.changeUseAfterManifest(U, *NewV)) |
0 |
6543 |
if (A.changeUseAfterManifest(U, *NewV)) |
0 |
| 6544 |
Changed = ChangeStatus::CHANGED; |
0 |
6544 |
Changed = ChangeStatus::CHANGED; |
0 |
| 6545 |
} |
--- |
6545 |
} |
--- |
| 6546 |
|
--- |
6546 |
|
--- |
| 6547 |
return Changed | AAValueSimplify::manifest(A); |
0 |
6547 |
return Changed | AAValueSimplify::manifest(A); |
0 |
| 6548 |
} |
--- |
6548 |
} |
--- |
| 6549 |
|
--- |
6549 |
|
--- |
| 6550 |
void trackStatistics() const override { |
0 |
6550 |
void trackStatistics() const override { |
0 |
| 6551 |
STATS_DECLTRACK_CSARG_ATTR(value_simplify) |
0 |
6551 |
STATS_DECLTRACK_CSARG_ATTR(value_simplify) |
0 |
| 6552 |
} |
0 |
6552 |
} |
0 |
| 6553 |
}; |
--- |
6553 |
}; |
--- |
| 6554 |
} // namespace |
--- |
6554 |
} // namespace |
--- |
| 6555 |
|
--- |
6555 |
|
--- |
| 6556 |
/// ----------------------- Heap-To-Stack Conversion --------------------------- |
--- |
6556 |
/// ----------------------- Heap-To-Stack Conversion --------------------------- |
--- |
| 6557 |
namespace { |
--- |
6557 |
namespace { |
--- |
| 6558 |
struct AAHeapToStackFunction final : public AAHeapToStack { |
--- |
6558 |
struct AAHeapToStackFunction final : public AAHeapToStack { |
--- |
| 6559 |
|
--- |
6559 |
|
--- |
| 6560 |
struct AllocationInfo { |
--- |
6560 |
struct AllocationInfo { |
--- |
| 6561 |
/// The call that allocates the memory. |
--- |
6561 |
/// The call that allocates the memory. |
--- |
| 6562 |
CallBase *const CB; |
--- |
6562 |
CallBase *const CB; |
--- |
| 6563 |
|
--- |
6563 |
|
--- |
| 6564 |
/// The library function id for the allocation. |
--- |
6564 |
/// The library function id for the allocation. |
--- |
| 6565 |
LibFunc LibraryFunctionId = NotLibFunc; |
--- |
6565 |
LibFunc LibraryFunctionId = NotLibFunc; |
--- |
| 6566 |
|
--- |
6566 |
|
--- |
| 6567 |
/// The status wrt. a rewrite. |
--- |
6567 |
/// The status wrt. a rewrite. |
--- |
| 6568 |
enum { |
--- |
6568 |
enum { |
--- |
| 6569 |
STACK_DUE_TO_USE, |
--- |
6569 |
STACK_DUE_TO_USE, |
--- |
| 6570 |
STACK_DUE_TO_FREE, |
--- |
6570 |
STACK_DUE_TO_FREE, |
--- |
| 6571 |
INVALID, |
--- |
6571 |
INVALID, |
--- |
| 6572 |
} Status = STACK_DUE_TO_USE; |
--- |
6572 |
} Status = STACK_DUE_TO_USE; |
--- |
| 6573 |
|
--- |
6573 |
|
--- |
| 6574 |
/// Flag to indicate if we encountered a use that might free this allocation |
--- |
6574 |
/// Flag to indicate if we encountered a use that might free this allocation |
--- |
| 6575 |
/// but which is not in the deallocation infos. |
--- |
6575 |
/// but which is not in the deallocation infos. |
--- |
| 6576 |
bool HasPotentiallyFreeingUnknownUses = false; |
--- |
6576 |
bool HasPotentiallyFreeingUnknownUses = false; |
--- |
| 6577 |
|
--- |
6577 |
|
--- |
| 6578 |
/// Flag to indicate that we should place the new alloca in the function |
--- |
6578 |
/// Flag to indicate that we should place the new alloca in the function |
--- |
| 6579 |
/// entry block rather than where the call site (CB) is. |
--- |
6579 |
/// entry block rather than where the call site (CB) is. |
--- |
| 6580 |
bool MoveAllocaIntoEntry = true; |
--- |
6580 |
bool MoveAllocaIntoEntry = true; |
--- |
| 6581 |
|
--- |
6581 |
|
--- |
| 6582 |
/// The set of free calls that use this allocation. |
--- |
6582 |
/// The set of free calls that use this allocation. |
--- |
| 6583 |
SmallSetVector PotentialFreeCalls{}; |
--- |
6583 |
SmallSetVector PotentialFreeCalls{}; |
--- |
| 6584 |
}; |
--- |
6584 |
}; |
--- |
| 6585 |
|
--- |
6585 |
|
--- |
| 6586 |
struct DeallocationInfo { |
--- |
6586 |
struct DeallocationInfo { |
--- |
| 6587 |
/// The call that deallocates the memory. |
--- |
6587 |
/// The call that deallocates the memory. |
--- |
| 6588 |
CallBase *const CB; |
--- |
6588 |
CallBase *const CB; |
--- |
| 6589 |
/// The value freed by the call. |
--- |
6589 |
/// The value freed by the call. |
--- |
| 6590 |
Value *FreedOp; |
--- |
6590 |
Value *FreedOp; |
--- |
| 6591 |
|
--- |
6591 |
|
--- |
| 6592 |
/// Flag to indicate if we don't know all objects this deallocation might |
--- |
6592 |
/// Flag to indicate if we don't know all objects this deallocation might |
--- |
| 6593 |
/// free. |
--- |
6593 |
/// free. |
--- |
| 6594 |
bool MightFreeUnknownObjects = false; |
--- |
6594 |
bool MightFreeUnknownObjects = false; |
--- |
| 6595 |
|
--- |
6595 |
|
--- |
| 6596 |
/// The set of allocation calls that are potentially freed. |
--- |
6596 |
/// The set of allocation calls that are potentially freed. |
--- |
| 6597 |
SmallSetVector PotentialAllocationCalls{}; |
--- |
6597 |
SmallSetVector PotentialAllocationCalls{}; |
--- |
| 6598 |
}; |
--- |
6598 |
}; |
--- |
| 6599 |
|
--- |
6599 |
|
--- |
| 6600 |
AAHeapToStackFunction(const IRPosition &IRP, Attributor &A) |
0 |
6600 |
AAHeapToStackFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 6601 |
: AAHeapToStack(IRP, A) {} |
0 |
6601 |
: AAHeapToStack(IRP, A) {} |
0 |
| 6602 |
|
--- |
6602 |
|
--- |
| 6603 |
~AAHeapToStackFunction() { |
0 |
6603 |
~AAHeapToStackFunction() { |
0 |
| 6604 |
// Ensure we call the destructor so we release any memory allocated in the |
--- |
6604 |
// Ensure we call the destructor so we release any memory allocated in the |
--- |
| 6605 |
// sets. |
--- |
6605 |
// sets. |
--- |
| 6606 |
for (auto &It : AllocationInfos) |
0 |
6606 |
for (auto &It : AllocationInfos) |
0 |
| 6607 |
It.second->~AllocationInfo(); |
0 |
6607 |
It.second->~AllocationInfo(); |
0 |
| 6608 |
for (auto &It : DeallocationInfos) |
0 |
6608 |
for (auto &It : DeallocationInfos) |
0 |
| 6609 |
It.second->~DeallocationInfo(); |
0 |
6609 |
It.second->~DeallocationInfo(); |
0 |
| 6610 |
} |
0 |
6610 |
} |
0 |
| 6611 |
|
--- |
6611 |
|
--- |
| 6612 |
void initialize(Attributor &A) override { |
0 |
6612 |
void initialize(Attributor &A) override { |
0 |
| 6613 |
AAHeapToStack::initialize(A); |
0 |
6613 |
AAHeapToStack::initialize(A); |
0 |
| 6614 |
|
--- |
6614 |
|
--- |
| 6615 |
const Function *F = getAnchorScope(); |
0 |
6615 |
const Function *F = getAnchorScope(); |
0 |
| 6616 |
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F); |
0 |
6616 |
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F); |
0 |
| 6617 |
|
--- |
6617 |
|
--- |
| 6618 |
auto AllocationIdentifierCB = [&](Instruction &I) { |
0 |
6618 |
auto AllocationIdentifierCB = [&](Instruction &I) { |
0 |
| 6619 |
CallBase *CB = dyn_cast(&I); |
0 |
6619 |
CallBase *CB = dyn_cast(&I); |
0 |
| 6620 |
if (!CB) |
0 |
6620 |
if (!CB) |
0 |
| 6621 |
return true; |
0 |
6621 |
return true; |
0 |
| 6622 |
if (Value *FreedOp = getFreedOperand(CB, TLI)) { |
0 |
6622 |
if (Value *FreedOp = getFreedOperand(CB, TLI)) { |
0 |
| 6623 |
DeallocationInfos[CB] = new (A.Allocator) DeallocationInfo{CB, FreedOp}; |
0 |
6623 |
DeallocationInfos[CB] = new (A.Allocator) DeallocationInfo{CB, FreedOp}; |
0 |
| 6624 |
return true; |
0 |
6624 |
return true; |
0 |
| 6625 |
} |
--- |
6625 |
} |
--- |
| 6626 |
// To do heap to stack, we need to know that the allocation itself is |
--- |
6626 |
// To do heap to stack, we need to know that the allocation itself is |
--- |
| 6627 |
// removable once uses are rewritten, and that we can initialize the |
--- |
6627 |
// removable once uses are rewritten, and that we can initialize the |
--- |
| 6628 |
// alloca to the same pattern as the original allocation result. |
--- |
6628 |
// alloca to the same pattern as the original allocation result. |
--- |
| 6629 |
if (isRemovableAlloc(CB, TLI)) { |
0 |
6629 |
if (isRemovableAlloc(CB, TLI)) { |
0 |
| 6630 |
auto *I8Ty = Type::getInt8Ty(CB->getParent()->getContext()); |
0 |
6630 |
auto *I8Ty = Type::getInt8Ty(CB->getParent()->getContext()); |
0 |
| 6631 |
if (nullptr != getInitialValueOfAllocation(CB, TLI, I8Ty)) { |
0 |
6631 |
if (nullptr != getInitialValueOfAllocation(CB, TLI, I8Ty)) { |
0 |
| 6632 |
AllocationInfo *AI = new (A.Allocator) AllocationInfo{CB}; |
0 |
6632 |
AllocationInfo *AI = new (A.Allocator) AllocationInfo{CB}; |
0 |
| 6633 |
AllocationInfos[CB] = AI; |
0 |
6633 |
AllocationInfos[CB] = AI; |
0 |
| 6634 |
if (TLI) |
0 |
6634 |
if (TLI) |
0 |
| 6635 |
TLI->getLibFunc(*CB, AI->LibraryFunctionId); |
0 |
6635 |
TLI->getLibFunc(*CB, AI->LibraryFunctionId); |
0 |
| 6636 |
} |
--- |
6636 |
} |
--- |
| 6637 |
} |
--- |
6637 |
} |
--- |
| 6638 |
return true; |
0 |
6638 |
return true; |
0 |
| 6639 |
}; |
0 |
6639 |
}; |
0 |
| 6640 |
|
--- |
6640 |
|
--- |
| 6641 |
bool UsedAssumedInformation = false; |
0 |
6641 |
bool UsedAssumedInformation = false; |
0 |
| 6642 |
bool Success = A.checkForAllCallLikeInstructions( |
0 |
6642 |
bool Success = A.checkForAllCallLikeInstructions( |
0 |
| 6643 |
AllocationIdentifierCB, *this, UsedAssumedInformation, |
--- |
6643 |
AllocationIdentifierCB, *this, UsedAssumedInformation, |
--- |
| 6644 |
/* CheckBBLivenessOnly */ false, |
--- |
6644 |
/* CheckBBLivenessOnly */ false, |
--- |
| 6645 |
/* CheckPotentiallyDead */ true); |
--- |
6645 |
/* CheckPotentiallyDead */ true); |
--- |
| 6646 |
(void)Success; |
--- |
6646 |
(void)Success; |
--- |
| 6647 |
assert(Success && "Did not expect the call base visit callback to fail!"); |
0 |
6647 |
assert(Success && "Did not expect the call base visit callback to fail!"); |
0 |
| 6648 |
|
--- |
6648 |
|
--- |
| 6649 |
Attributor::SimplifictionCallbackTy SCB = |
--- |
6649 |
Attributor::SimplifictionCallbackTy SCB = |
--- |
| 6650 |
[](const IRPosition &, const AbstractAttribute *, |
0 |
6650 |
[](const IRPosition &, const AbstractAttribute *, |
0 |
| 6651 |
bool &) -> std::optional { return nullptr; }; |
0 |
6651 |
bool &) -> std::optional { return nullptr; }; |
0 |
| 6652 |
for (const auto &It : AllocationInfos) |
0 |
6652 |
for (const auto &It : AllocationInfos) |
0 |
| 6653 |
A.registerSimplificationCallback(IRPosition::callsite_returned(*It.first), |
0 |
6653 |
A.registerSimplificationCallback(IRPosition::callsite_returned(*It.first), |
0 |
| 6654 |
SCB); |
--- |
6654 |
SCB); |
--- |
| 6655 |
for (const auto &It : DeallocationInfos) |
0 |
6655 |
for (const auto &It : DeallocationInfos) |
0 |
| 6656 |
A.registerSimplificationCallback(IRPosition::callsite_returned(*It.first), |
0 |
6656 |
A.registerSimplificationCallback(IRPosition::callsite_returned(*It.first), |
0 |
| 6657 |
SCB); |
--- |
6657 |
SCB); |
--- |
| 6658 |
} |
0 |
6658 |
} |
0 |
| 6659 |
|
--- |
6659 |
|
--- |
| 6660 |
const std::string getAsStr(Attributor *A) const override { |
0 |
6660 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 6661 |
unsigned NumH2SMallocs = 0, NumInvalidMallocs = 0; |
0 |
6661 |
unsigned NumH2SMallocs = 0, NumInvalidMallocs = 0; |
0 |
| 6662 |
for (const auto &It : AllocationInfos) { |
0 |
6662 |
for (const auto &It : AllocationInfos) { |
0 |
| 6663 |
if (It.second->Status == AllocationInfo::INVALID) |
0 |
6663 |
if (It.second->Status == AllocationInfo::INVALID) |
0 |
| 6664 |
++NumInvalidMallocs; |
0 |
6664 |
++NumInvalidMallocs; |
0 |
| 6665 |
else |
--- |
6665 |
else |
--- |
| 6666 |
++NumH2SMallocs; |
0 |
6666 |
++NumH2SMallocs; |
0 |
| 6667 |
} |
--- |
6667 |
} |
--- |
| 6668 |
return "[H2S] Mallocs Good/Bad: " + std::to_string(NumH2SMallocs) + "/" + |
0 |
6668 |
return "[H2S] Mallocs Good/Bad: " + std::to_string(NumH2SMallocs) + "/" + |
0 |
| 6669 |
std::to_string(NumInvalidMallocs); |
0 |
6669 |
std::to_string(NumInvalidMallocs); |
0 |
| 6670 |
} |
--- |
6670 |
} |
--- |
| 6671 |
|
--- |
6671 |
|
--- |
| 6672 |
/// See AbstractAttribute::trackStatistics(). |
--- |
6672 |
/// See AbstractAttribute::trackStatistics(). |
--- |
| 6673 |
void trackStatistics() const override { |
0 |
6673 |
void trackStatistics() const override { |
0 |
| 6674 |
STATS_DECL( |
--- |
6674 |
STATS_DECL( |
--- |
| 6675 |
MallocCalls, Function, |
--- |
6675 |
MallocCalls, Function, |
--- |
| 6676 |
"Number of malloc/calloc/aligned_alloc calls converted to allocas"); |
--- |
6676 |
"Number of malloc/calloc/aligned_alloc calls converted to allocas"); |
--- |
| 6677 |
for (const auto &It : AllocationInfos) |
0 |
6677 |
for (const auto &It : AllocationInfos) |
0 |
| 6678 |
if (It.second->Status != AllocationInfo::INVALID) |
0 |
6678 |
if (It.second->Status != AllocationInfo::INVALID) |
0 |
| 6679 |
++BUILD_STAT_NAME(MallocCalls, Function); |
0 |
6679 |
++BUILD_STAT_NAME(MallocCalls, Function); |
0 |
| 6680 |
} |
0 |
6680 |
} |
0 |
| 6681 |
|
--- |
6681 |
|
--- |
| 6682 |
bool isAssumedHeapToStack(const CallBase &CB) const override { |
0 |
6682 |
bool isAssumedHeapToStack(const CallBase &CB) const override { |
0 |
| 6683 |
if (isValidState()) |
0 |
6683 |
if (isValidState()) |
0 |
| 6684 |
if (AllocationInfo *AI = |
0 |
6684 |
if (AllocationInfo *AI = |
0 |
| 6685 |
AllocationInfos.lookup(const_cast(&CB))) |
0 |
6685 |
AllocationInfos.lookup(const_cast(&CB))) |
0 |
| 6686 |
return AI->Status != AllocationInfo::INVALID; |
0 |
6686 |
return AI->Status != AllocationInfo::INVALID; |
0 |
| 6687 |
return false; |
0 |
6687 |
return false; |
0 |
| 6688 |
} |
--- |
6688 |
} |
--- |
| 6689 |
|
--- |
6689 |
|
--- |
| 6690 |
bool isAssumedHeapToStackRemovedFree(CallBase &CB) const override { |
0 |
6690 |
bool isAssumedHeapToStackRemovedFree(CallBase &CB) const override { |
0 |
| 6691 |
if (!isValidState()) |
0 |
6691 |
if (!isValidState()) |
0 |
| 6692 |
return false; |
0 |
6692 |
return false; |
0 |
| 6693 |
|
--- |
6693 |
|
--- |
| 6694 |
for (const auto &It : AllocationInfos) { |
0 |
6694 |
for (const auto &It : AllocationInfos) { |
0 |
| 6695 |
AllocationInfo &AI = *It.second; |
0 |
6695 |
AllocationInfo &AI = *It.second; |
0 |
| 6696 |
if (AI.Status == AllocationInfo::INVALID) |
0 |
6696 |
if (AI.Status == AllocationInfo::INVALID) |
0 |
| 6697 |
continue; |
0 |
6697 |
continue; |
0 |
| 6698 |
|
--- |
6698 |
|
--- |
| 6699 |
if (AI.PotentialFreeCalls.count(&CB)) |
0 |
6699 |
if (AI.PotentialFreeCalls.count(&CB)) |
0 |
| 6700 |
return true; |
0 |
6700 |
return true; |
0 |
| 6701 |
} |
--- |
6701 |
} |
--- |
| 6702 |
|
--- |
6702 |
|
--- |
| 6703 |
return false; |
0 |
6703 |
return false; |
0 |
| 6704 |
} |
--- |
6704 |
} |
--- |
| 6705 |
|
--- |
6705 |
|
--- |
| 6706 |
ChangeStatus manifest(Attributor &A) override { |
0 |
6706 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 6707 |
assert(getState().isValidState() && |
0 |
6707 |
assert(getState().isValidState() && |
0 |
| 6708 |
"Attempted to manifest an invalid state!"); |
--- |
6708 |
"Attempted to manifest an invalid state!"); |
--- |
| 6709 |
|
--- |
6709 |
|
--- |
| 6710 |
ChangeStatus HasChanged = ChangeStatus::UNCHANGED; |
0 |
6710 |
ChangeStatus HasChanged = ChangeStatus::UNCHANGED; |
0 |
| 6711 |
Function *F = getAnchorScope(); |
0 |
6711 |
Function *F = getAnchorScope(); |
0 |
| 6712 |
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F); |
0 |
6712 |
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F); |
0 |
| 6713 |
|
--- |
6713 |
|
--- |
| 6714 |
for (auto &It : AllocationInfos) { |
0 |
6714 |
for (auto &It : AllocationInfos) { |
0 |
| 6715 |
AllocationInfo &AI = *It.second; |
0 |
6715 |
AllocationInfo &AI = *It.second; |
0 |
| 6716 |
if (AI.Status == AllocationInfo::INVALID) |
0 |
6716 |
if (AI.Status == AllocationInfo::INVALID) |
0 |
| 6717 |
continue; |
0 |
6717 |
continue; |
0 |
| 6718 |
|
--- |
6718 |
|
--- |
| 6719 |
for (CallBase *FreeCall : AI.PotentialFreeCalls) { |
0 |
6719 |
for (CallBase *FreeCall : AI.PotentialFreeCalls) { |
0 |
| 6720 |
LLVM_DEBUG(dbgs() << "H2S: Removing free call: " << *FreeCall << "\n"); |
0 |
6720 |
LLVM_DEBUG(dbgs() << "H2S: Removing free call: " << *FreeCall << "\n"); |
0 |
| 6721 |
A.deleteAfterManifest(*FreeCall); |
0 |
6721 |
A.deleteAfterManifest(*FreeCall); |
0 |
| 6722 |
HasChanged = ChangeStatus::CHANGED; |
0 |
6722 |
HasChanged = ChangeStatus::CHANGED; |
0 |
| 6723 |
} |
--- |
6723 |
} |
--- |
| 6724 |
|
--- |
6724 |
|
--- |
| 6725 |
LLVM_DEBUG(dbgs() << "H2S: Removing malloc-like call: " << *AI.CB |
0 |
6725 |
LLVM_DEBUG(dbgs() << "H2S: Removing malloc-like call: " << *AI.CB |
0 |
| 6726 |
<< "\n"); |
--- |
6726 |
<< "\n"); |
--- |
| 6727 |
|
--- |
6727 |
|
--- |
| 6728 |
auto Remark = [&](OptimizationRemark OR) { |
0 |
6728 |
auto Remark = [&](OptimizationRemark OR) { |
0 |
| 6729 |
LibFunc IsAllocShared; |
--- |
6729 |
LibFunc IsAllocShared; |
--- |
| 6730 |
if (TLI->getLibFunc(*AI.CB, IsAllocShared)) |
0 |
6730 |
if (TLI->getLibFunc(*AI.CB, IsAllocShared)) |
0 |
| 6731 |
if (IsAllocShared == LibFunc___kmpc_alloc_shared) |
0 |
6731 |
if (IsAllocShared == LibFunc___kmpc_alloc_shared) |
0 |
| 6732 |
return OR << "Moving globalized variable to the stack."; |
0 |
6732 |
return OR << "Moving globalized variable to the stack."; |
0 |
| 6733 |
return OR << "Moving memory allocation from the heap to the stack."; |
0 |
6733 |
return OR << "Moving memory allocation from the heap to the stack."; |
0 |
| 6734 |
}; |
0 |
6734 |
}; |
0 |
| 6735 |
if (AI.LibraryFunctionId == LibFunc___kmpc_alloc_shared) |
0 |
6735 |
if (AI.LibraryFunctionId == LibFunc___kmpc_alloc_shared) |
0 |
| 6736 |
A.emitRemark(AI.CB, "OMP110", Remark); |
0 |
6736 |
A.emitRemark(AI.CB, "OMP110", Remark); |
0 |
| 6737 |
else |
--- |
6737 |
else |
--- |
| 6738 |
A.emitRemark(AI.CB, "HeapToStack", Remark); |
0 |
6738 |
A.emitRemark(AI.CB, "HeapToStack", Remark); |
0 |
| 6739 |
|
--- |
6739 |
|
--- |
| 6740 |
const DataLayout &DL = A.getInfoCache().getDL(); |
0 |
6740 |
const DataLayout &DL = A.getInfoCache().getDL(); |
0 |
| 6741 |
Value *Size; |
--- |
6741 |
Value *Size; |
--- |
| 6742 |
std::optional SizeAPI = getSize(A, *this, AI); |
0 |
6742 |
std::optional SizeAPI = getSize(A, *this, AI); |
0 |
| 6743 |
if (SizeAPI) { |
0 |
6743 |
if (SizeAPI) { |
0 |
| 6744 |
Size = ConstantInt::get(AI.CB->getContext(), *SizeAPI); |
0 |
6744 |
Size = ConstantInt::get(AI.CB->getContext(), *SizeAPI); |
0 |
| 6745 |
} else { |
--- |
6745 |
} else { |
--- |
| 6746 |
LLVMContext &Ctx = AI.CB->getContext(); |
0 |
6746 |
LLVMContext &Ctx = AI.CB->getContext(); |
0 |
| 6747 |
ObjectSizeOpts Opts; |
0 |
6747 |
ObjectSizeOpts Opts; |
0 |
| 6748 |
ObjectSizeOffsetEvaluator Eval(DL, TLI, Ctx, Opts); |
0 |
6748 |
ObjectSizeOffsetEvaluator Eval(DL, TLI, Ctx, Opts); |
0 |
| 6749 |
SizeOffsetEvalType SizeOffsetPair = Eval.compute(AI.CB); |
0 |
6749 |
SizeOffsetEvalType SizeOffsetPair = Eval.compute(AI.CB); |
0 |
| 6750 |
assert(SizeOffsetPair != ObjectSizeOffsetEvaluator::unknown() && |
0 |
6750 |
assert(SizeOffsetPair != ObjectSizeOffsetEvaluator::unknown() && |
0 |
| 6751 |
cast(SizeOffsetPair.second)->isZero()); |
--- |
6751 |
cast(SizeOffsetPair.second)->isZero()); |
--- |
| 6752 |
Size = SizeOffsetPair.first; |
0 |
6752 |
Size = SizeOffsetPair.first; |
0 |
| 6753 |
} |
0 |
6753 |
} |
0 |
| 6754 |
|
--- |
6754 |
|
--- |
| 6755 |
Instruction *IP = |
--- |
6755 |
Instruction *IP = |
--- |
| 6756 |
AI.MoveAllocaIntoEntry ? &F->getEntryBlock().front() : AI.CB; |
0 |
6756 |
AI.MoveAllocaIntoEntry ? &F->getEntryBlock().front() : AI.CB; |
0 |
| 6757 |
|
--- |
6757 |
|
--- |
| 6758 |
Align Alignment(1); |
0 |
6758 |
Align Alignment(1); |
0 |
| 6759 |
if (MaybeAlign RetAlign = AI.CB->getRetAlign()) |
0 |
6759 |
if (MaybeAlign RetAlign = AI.CB->getRetAlign()) |
0 |
| 6760 |
Alignment = std::max(Alignment, *RetAlign); |
0 |
6760 |
Alignment = std::max(Alignment, *RetAlign); |
0 |
| 6761 |
if (Value *Align = getAllocAlignment(AI.CB, TLI)) { |
0 |
6761 |
if (Value *Align = getAllocAlignment(AI.CB, TLI)) { |
0 |
| 6762 |
std::optional AlignmentAPI = getAPInt(A, *this, *Align); |
0 |
6762 |
std::optional AlignmentAPI = getAPInt(A, *this, *Align); |
0 |
| 6763 |
assert(AlignmentAPI && AlignmentAPI->getZExtValue() > 0 && |
0 |
6763 |
assert(AlignmentAPI && AlignmentAPI->getZExtValue() > 0 && |
0 |
| 6764 |
"Expected an alignment during manifest!"); |
--- |
6764 |
"Expected an alignment during manifest!"); |
--- |
| 6765 |
Alignment = |
0 |
6765 |
Alignment = |
0 |
| 6766 |
std::max(Alignment, assumeAligned(AlignmentAPI->getZExtValue())); |
0 |
6766 |
std::max(Alignment, assumeAligned(AlignmentAPI->getZExtValue())); |
0 |
| 6767 |
} |
0 |
6767 |
} |
0 |
| 6768 |
|
--- |
6768 |
|
--- |
| 6769 |
// TODO: Hoist the alloca towards the function entry. |
--- |
6769 |
// TODO: Hoist the alloca towards the function entry. |
--- |
| 6770 |
unsigned AS = DL.getAllocaAddrSpace(); |
0 |
6770 |
unsigned AS = DL.getAllocaAddrSpace(); |
0 |
| 6771 |
Instruction *Alloca = |
--- |
6771 |
Instruction *Alloca = |
--- |
| 6772 |
new AllocaInst(Type::getInt8Ty(F->getContext()), AS, Size, Alignment, |
0 |
6772 |
new AllocaInst(Type::getInt8Ty(F->getContext()), AS, Size, Alignment, |
0 |
| 6773 |
AI.CB->getName() + ".h2s", IP); |
0 |
6773 |
AI.CB->getName() + ".h2s", IP); |
0 |
| 6774 |
|
--- |
6774 |
|
--- |
| 6775 |
if (Alloca->getType() != AI.CB->getType()) |
0 |
6775 |
if (Alloca->getType() != AI.CB->getType()) |
0 |
| 6776 |
Alloca = BitCastInst::CreatePointerBitCastOrAddrSpaceCast( |
0 |
6776 |
Alloca = BitCastInst::CreatePointerBitCastOrAddrSpaceCast( |
0 |
| 6777 |
Alloca, AI.CB->getType(), "malloc_cast", AI.CB); |
0 |
6777 |
Alloca, AI.CB->getType(), "malloc_cast", AI.CB); |
0 |
| 6778 |
|
--- |
6778 |
|
--- |
| 6779 |
auto *I8Ty = Type::getInt8Ty(F->getContext()); |
0 |
6779 |
auto *I8Ty = Type::getInt8Ty(F->getContext()); |
0 |
| 6780 |
auto *InitVal = getInitialValueOfAllocation(AI.CB, TLI, I8Ty); |
0 |
6780 |
auto *InitVal = getInitialValueOfAllocation(AI.CB, TLI, I8Ty); |
0 |
| 6781 |
assert(InitVal && |
0 |
6781 |
assert(InitVal && |
0 |
| 6782 |
"Must be able to materialize initial memory state of allocation"); |
--- |
6782 |
"Must be able to materialize initial memory state of allocation"); |
--- |
| 6783 |
|
--- |
6783 |
|
--- |
| 6784 |
A.changeAfterManifest(IRPosition::inst(*AI.CB), *Alloca); |
0 |
6784 |
A.changeAfterManifest(IRPosition::inst(*AI.CB), *Alloca); |
0 |
| 6785 |
|
--- |
6785 |
|
--- |
| 6786 |
if (auto *II = dyn_cast(AI.CB)) { |
0 |
6786 |
if (auto *II = dyn_cast(AI.CB)) { |
0 |
| 6787 |
auto *NBB = II->getNormalDest(); |
0 |
6787 |
auto *NBB = II->getNormalDest(); |
0 |
| 6788 |
BranchInst::Create(NBB, AI.CB->getParent()); |
0 |
6788 |
BranchInst::Create(NBB, AI.CB->getParent()); |
0 |
| 6789 |
A.deleteAfterManifest(*AI.CB); |
0 |
6789 |
A.deleteAfterManifest(*AI.CB); |
0 |
| 6790 |
} else { |
--- |
6790 |
} else { |
--- |
| 6791 |
A.deleteAfterManifest(*AI.CB); |
0 |
6791 |
A.deleteAfterManifest(*AI.CB); |
0 |
| 6792 |
} |
--- |
6792 |
} |
--- |
| 6793 |
|
--- |
6793 |
|
--- |
| 6794 |
// Initialize the alloca with the same value as used by the allocation |
--- |
6794 |
// Initialize the alloca with the same value as used by the allocation |
--- |
| 6795 |
// function. We can skip undef as the initial value of an alloc is |
--- |
6795 |
// function. We can skip undef as the initial value of an alloc is |
--- |
| 6796 |
// undef, and the memset would simply end up being DSEd. |
--- |
6796 |
// undef, and the memset would simply end up being DSEd. |
--- |
| 6797 |
if (!isa(InitVal)) { |
0 |
6797 |
if (!isa(InitVal)) { |
0 |
| 6798 |
IRBuilder<> Builder(Alloca->getNextNode()); |
0 |
6798 |
IRBuilder<> Builder(Alloca->getNextNode()); |
0 |
| 6799 |
// TODO: Use alignment above if align!=1 |
--- |
6799 |
// TODO: Use alignment above if align!=1 |
--- |
| 6800 |
Builder.CreateMemSet(Alloca, InitVal, Size, std::nullopt); |
0 |
6800 |
Builder.CreateMemSet(Alloca, InitVal, Size, std::nullopt); |
0 |
| 6801 |
} |
0 |
6801 |
} |
0 |
| 6802 |
HasChanged = ChangeStatus::CHANGED; |
0 |
6802 |
HasChanged = ChangeStatus::CHANGED; |
0 |
| 6803 |
} |
0 |
6803 |
} |
0 |
| 6804 |
|
--- |
6804 |
|
--- |
| 6805 |
return HasChanged; |
0 |
6805 |
return HasChanged; |
0 |
| 6806 |
} |
--- |
6806 |
} |
--- |
| 6807 |
|
--- |
6807 |
|
--- |
| 6808 |
std::optional getAPInt(Attributor &A, const AbstractAttribute &AA, |
0 |
6808 |
std::optional getAPInt(Attributor &A, const AbstractAttribute &AA, |
0 |
| 6809 |
Value &V) { |
--- |
6809 |
Value &V) { |
--- |
| 6810 |
bool UsedAssumedInformation = false; |
0 |
6810 |
bool UsedAssumedInformation = false; |
0 |
| 6811 |
std::optional SimpleV = |
--- |
6811 |
std::optional SimpleV = |
--- |
| 6812 |
A.getAssumedConstant(V, AA, UsedAssumedInformation); |
0 |
6812 |
A.getAssumedConstant(V, AA, UsedAssumedInformation); |
0 |
| 6813 |
if (!SimpleV) |
0 |
6813 |
if (!SimpleV) |
0 |
| 6814 |
return APInt(64, 0); |
0 |
6814 |
return APInt(64, 0); |
0 |
| 6815 |
if (auto *CI = dyn_cast_or_null(*SimpleV)) |
0 |
6815 |
if (auto *CI = dyn_cast_or_null(*SimpleV)) |
0 |
| 6816 |
return CI->getValue(); |
0 |
6816 |
return CI->getValue(); |
0 |
| 6817 |
return std::nullopt; |
0 |
6817 |
return std::nullopt; |
0 |
| 6818 |
} |
--- |
6818 |
} |
--- |
| 6819 |
|
--- |
6819 |
|
--- |
| 6820 |
std::optional getSize(Attributor &A, const AbstractAttribute &AA, |
0 |
6820 |
std::optional getSize(Attributor &A, const AbstractAttribute &AA, |
0 |
| 6821 |
AllocationInfo &AI) { |
--- |
6821 |
AllocationInfo &AI) { |
--- |
| 6822 |
auto Mapper = [&](const Value *V) -> const Value * { |
0 |
6822 |
auto Mapper = [&](const Value *V) -> const Value * { |
0 |
| 6823 |
bool UsedAssumedInformation = false; |
0 |
6823 |
bool UsedAssumedInformation = false; |
0 |
| 6824 |
if (std::optional SimpleV = |
0 |
6824 |
if (std::optional SimpleV = |
0 |
| 6825 |
A.getAssumedConstant(*V, AA, UsedAssumedInformation)) |
0 |
6825 |
A.getAssumedConstant(*V, AA, UsedAssumedInformation)) |
0 |
| 6826 |
if (*SimpleV) |
0 |
6826 |
if (*SimpleV) |
0 |
| 6827 |
return *SimpleV; |
0 |
6827 |
return *SimpleV; |
0 |
| 6828 |
return V; |
0 |
6828 |
return V; |
0 |
| 6829 |
}; |
0 |
6829 |
}; |
0 |
| 6830 |
|
--- |
6830 |
|
--- |
| 6831 |
const Function *F = getAnchorScope(); |
0 |
6831 |
const Function *F = getAnchorScope(); |
0 |
| 6832 |
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F); |
0 |
6832 |
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F); |
0 |
| 6833 |
return getAllocSize(AI.CB, TLI, Mapper); |
0 |
6833 |
return getAllocSize(AI.CB, TLI, Mapper); |
0 |
| 6834 |
} |
--- |
6834 |
} |
--- |
| 6835 |
|
--- |
6835 |
|
--- |
| 6836 |
/// Collection of all malloc-like calls in a function with associated |
--- |
6836 |
/// Collection of all malloc-like calls in a function with associated |
--- |
| 6837 |
/// information. |
--- |
6837 |
/// information. |
--- |
| 6838 |
MapVector AllocationInfos; |
--- |
6838 |
MapVector AllocationInfos; |
--- |
| 6839 |
|
--- |
6839 |
|
--- |
| 6840 |
/// Collection of all free-like calls in a function with associated |
--- |
6840 |
/// Collection of all free-like calls in a function with associated |
--- |
| 6841 |
/// information. |
--- |
6841 |
/// information. |
--- |
| 6842 |
MapVector DeallocationInfos; |
--- |
6842 |
MapVector DeallocationInfos; |
--- |
| 6843 |
|
--- |
6843 |
|
--- |
| 6844 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
6844 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
| 6845 |
}; |
--- |
6845 |
}; |
--- |
| 6846 |
|
--- |
6846 |
|
--- |
| 6847 |
ChangeStatus AAHeapToStackFunction::updateImpl(Attributor &A) { |
0 |
6847 |
ChangeStatus AAHeapToStackFunction::updateImpl(Attributor &A) { |
0 |
| 6848 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
6848 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 6849 |
const Function *F = getAnchorScope(); |
0 |
6849 |
const Function *F = getAnchorScope(); |
0 |
| 6850 |
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F); |
0 |
6850 |
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F); |
0 |
| 6851 |
|
--- |
6851 |
|
--- |
| 6852 |
const auto *LivenessAA = |
--- |
6852 |
const auto *LivenessAA = |
--- |
| 6853 |
A.getAAFor(*this, IRPosition::function(*F), DepClassTy::NONE); |
0 |
6853 |
A.getAAFor(*this, IRPosition::function(*F), DepClassTy::NONE); |
0 |
| 6854 |
|
--- |
6854 |
|
--- |
| 6855 |
MustBeExecutedContextExplorer *Explorer = |
--- |
6855 |
MustBeExecutedContextExplorer *Explorer = |
--- |
| 6856 |
A.getInfoCache().getMustBeExecutedContextExplorer(); |
0 |
6856 |
A.getInfoCache().getMustBeExecutedContextExplorer(); |
0 |
| 6857 |
|
--- |
6857 |
|
--- |
| 6858 |
bool StackIsAccessibleByOtherThreads = |
--- |
6858 |
bool StackIsAccessibleByOtherThreads = |
--- |
| 6859 |
A.getInfoCache().stackIsAccessibleByOtherThreads(); |
0 |
6859 |
A.getInfoCache().stackIsAccessibleByOtherThreads(); |
0 |
| 6860 |
|
--- |
6860 |
|
--- |
| 6861 |
LoopInfo *LI = |
--- |
6861 |
LoopInfo *LI = |
--- |
| 6862 |
A.getInfoCache().getAnalysisResultForFunction(*F); |
0 |
6862 |
A.getInfoCache().getAnalysisResultForFunction(*F); |
0 |
| 6863 |
std::optional MayContainIrreducibleControl; |
0 |
6863 |
std::optional MayContainIrreducibleControl; |
0 |
| 6864 |
auto IsInLoop = [&](BasicBlock &BB) { |
0 |
6864 |
auto IsInLoop = [&](BasicBlock &BB) { |
0 |
| 6865 |
if (&F->getEntryBlock() == &BB) |
0 |
6865 |
if (&F->getEntryBlock() == &BB) |
0 |
| 6866 |
return false; |
0 |
6866 |
return false; |
0 |
| 6867 |
if (!MayContainIrreducibleControl.has_value()) |
0 |
6867 |
if (!MayContainIrreducibleControl.has_value()) |
0 |
| 6868 |
MayContainIrreducibleControl = mayContainIrreducibleControl(*F, LI); |
0 |
6868 |
MayContainIrreducibleControl = mayContainIrreducibleControl(*F, LI); |
0 |
| 6869 |
if (*MayContainIrreducibleControl) |
0 |
6869 |
if (*MayContainIrreducibleControl) |
0 |
| 6870 |
return true; |
0 |
6870 |
return true; |
0 |
| 6871 |
if (!LI) |
0 |
6871 |
if (!LI) |
0 |
| 6872 |
return true; |
0 |
6872 |
return true; |
0 |
| 6873 |
return LI->getLoopFor(&BB) != nullptr; |
0 |
6873 |
return LI->getLoopFor(&BB) != nullptr; |
0 |
| 6874 |
}; |
0 |
6874 |
}; |
0 |
| 6875 |
|
--- |
6875 |
|
--- |
| 6876 |
// Flag to ensure we update our deallocation information at most once per |
--- |
6876 |
// Flag to ensure we update our deallocation information at most once per |
--- |
| 6877 |
// updateImpl call and only if we use the free check reasoning. |
--- |
6877 |
// updateImpl call and only if we use the free check reasoning. |
--- |
| 6878 |
bool HasUpdatedFrees = false; |
0 |
6878 |
bool HasUpdatedFrees = false; |
0 |
| 6879 |
|
--- |
6879 |
|
--- |
| 6880 |
auto UpdateFrees = [&]() { |
0 |
6880 |
auto UpdateFrees = [&]() { |
0 |
| 6881 |
HasUpdatedFrees = true; |
0 |
6881 |
HasUpdatedFrees = true; |
0 |
| 6882 |
|
--- |
6882 |
|
--- |
| 6883 |
for (auto &It : DeallocationInfos) { |
0 |
6883 |
for (auto &It : DeallocationInfos) { |
0 |
| 6884 |
DeallocationInfo &DI = *It.second; |
0 |
6884 |
DeallocationInfo &DI = *It.second; |
0 |
| 6885 |
// For now we cannot use deallocations that have unknown inputs, skip |
--- |
6885 |
// For now we cannot use deallocations that have unknown inputs, skip |
--- |
| 6886 |
// them. |
--- |
6886 |
// them. |
--- |
| 6887 |
if (DI.MightFreeUnknownObjects) |
0 |
6887 |
if (DI.MightFreeUnknownObjects) |
0 |
| 6888 |
continue; |
0 |
6888 |
continue; |
0 |
| 6889 |
|
--- |
6889 |
|
--- |
| 6890 |
// No need to analyze dead calls, ignore them instead. |
--- |
6890 |
// No need to analyze dead calls, ignore them instead. |
--- |
| 6891 |
bool UsedAssumedInformation = false; |
0 |
6891 |
bool UsedAssumedInformation = false; |
0 |
| 6892 |
if (A.isAssumedDead(*DI.CB, this, LivenessAA, UsedAssumedInformation, |
0 |
6892 |
if (A.isAssumedDead(*DI.CB, this, LivenessAA, UsedAssumedInformation, |
0 |
| 6893 |
/* CheckBBLivenessOnly */ true)) |
--- |
6893 |
/* CheckBBLivenessOnly */ true)) |
--- |
| 6894 |
continue; |
0 |
6894 |
continue; |
0 |
| 6895 |
|
--- |
6895 |
|
--- |
| 6896 |
// Use the non-optimistic version to get the freed object. |
--- |
6896 |
// Use the non-optimistic version to get the freed object. |
--- |
| 6897 |
Value *Obj = getUnderlyingObject(DI.FreedOp); |
0 |
6897 |
Value *Obj = getUnderlyingObject(DI.FreedOp); |
0 |
| 6898 |
if (!Obj) { |
0 |
6898 |
if (!Obj) { |
0 |
| 6899 |
LLVM_DEBUG(dbgs() << "[H2S] Unknown underlying object for free!\n"); |
0 |
6899 |
LLVM_DEBUG(dbgs() << "[H2S] Unknown underlying object for free!\n"); |
0 |
| 6900 |
DI.MightFreeUnknownObjects = true; |
0 |
6900 |
DI.MightFreeUnknownObjects = true; |
0 |
| 6901 |
continue; |
0 |
6901 |
continue; |
0 |
| 6902 |
} |
--- |
6902 |
} |
--- |
| 6903 |
|
--- |
6903 |
|
--- |
| 6904 |
// Free of null and undef can be ignored as no-ops (or UB in the latter |
--- |
6904 |
// Free of null and undef can be ignored as no-ops (or UB in the latter |
--- |
| 6905 |
// case). |
--- |
6905 |
// case). |
--- |
| 6906 |
if (isa(Obj) || isa(Obj)) |
0 |
6906 |
if (isa(Obj) || isa(Obj)) |
0 |
| 6907 |
continue; |
0 |
6907 |
continue; |
0 |
| 6908 |
|
--- |
6908 |
|
--- |
| 6909 |
CallBase *ObjCB = dyn_cast(Obj); |
0 |
6909 |
CallBase *ObjCB = dyn_cast(Obj); |
0 |
| 6910 |
if (!ObjCB) { |
0 |
6910 |
if (!ObjCB) { |
0 |
| 6911 |
LLVM_DEBUG(dbgs() << "[H2S] Free of a non-call object: " << *Obj |
0 |
6911 |
LLVM_DEBUG(dbgs() << "[H2S] Free of a non-call object: " << *Obj |
0 |
| 6912 |
<< "\n"); |
--- |
6912 |
<< "\n"); |
--- |
| 6913 |
DI.MightFreeUnknownObjects = true; |
0 |
6913 |
DI.MightFreeUnknownObjects = true; |
0 |
| 6914 |
continue; |
0 |
6914 |
continue; |
0 |
| 6915 |
} |
--- |
6915 |
} |
--- |
| 6916 |
|
--- |
6916 |
|
--- |
| 6917 |
AllocationInfo *AI = AllocationInfos.lookup(ObjCB); |
0 |
6917 |
AllocationInfo *AI = AllocationInfos.lookup(ObjCB); |
0 |
| 6918 |
if (!AI) { |
0 |
6918 |
if (!AI) { |
0 |
| 6919 |
LLVM_DEBUG(dbgs() << "[H2S] Free of a non-allocation object: " << *Obj |
0 |
6919 |
LLVM_DEBUG(dbgs() << "[H2S] Free of a non-allocation object: " << *Obj |
0 |
| 6920 |
<< "\n"); |
--- |
6920 |
<< "\n"); |
--- |
| 6921 |
DI.MightFreeUnknownObjects = true; |
0 |
6921 |
DI.MightFreeUnknownObjects = true; |
0 |
| 6922 |
continue; |
0 |
6922 |
continue; |
0 |
| 6923 |
} |
--- |
6923 |
} |
--- |
| 6924 |
|
--- |
6924 |
|
--- |
| 6925 |
DI.PotentialAllocationCalls.insert(ObjCB); |
0 |
6925 |
DI.PotentialAllocationCalls.insert(ObjCB); |
0 |
| 6926 |
} |
--- |
6926 |
} |
--- |
| 6927 |
}; |
0 |
6927 |
}; |
0 |
| 6928 |
|
--- |
6928 |
|
--- |
| 6929 |
auto FreeCheck = [&](AllocationInfo &AI) { |
0 |
6929 |
auto FreeCheck = [&](AllocationInfo &AI) { |
0 |
| 6930 |
// If the stack is not accessible by other threads, the "must-free" logic |
--- |
6930 |
// If the stack is not accessible by other threads, the "must-free" logic |
--- |
| 6931 |
// doesn't apply as the pointer could be shared and needs to be places in |
--- |
6931 |
// doesn't apply as the pointer could be shared and needs to be places in |
--- |
| 6932 |
// "shareable" memory. |
--- |
6932 |
// "shareable" memory. |
--- |
| 6933 |
if (!StackIsAccessibleByOtherThreads) { |
0 |
6933 |
if (!StackIsAccessibleByOtherThreads) { |
0 |
| 6934 |
bool IsKnownNoSycn; |
--- |
6934 |
bool IsKnownNoSycn; |
--- |
| 6935 |
if (!AA::hasAssumedIRAttr( |
0 |
6935 |
if (!AA::hasAssumedIRAttr( |
0 |
| 6936 |
A, this, getIRPosition(), DepClassTy::OPTIONAL, IsKnownNoSycn)) { |
0 |
6936 |
A, this, getIRPosition(), DepClassTy::OPTIONAL, IsKnownNoSycn)) { |
0 |
| 6937 |
LLVM_DEBUG( |
0 |
6937 |
LLVM_DEBUG( |
0 |
| 6938 |
dbgs() << "[H2S] found an escaping use, stack is not accessible by " |
--- |
6938 |
dbgs() << "[H2S] found an escaping use, stack is not accessible by " |
--- |
| 6939 |
"other threads and function is not nosync:\n"); |
--- |
6939 |
"other threads and function is not nosync:\n"); |
--- |
| 6940 |
return false; |
0 |
6940 |
return false; |
0 |
| 6941 |
} |
--- |
6941 |
} |
--- |
| 6942 |
} |
--- |
6942 |
} |
--- |
| 6943 |
if (!HasUpdatedFrees) |
0 |
6943 |
if (!HasUpdatedFrees) |
0 |
| 6944 |
UpdateFrees(); |
0 |
6944 |
UpdateFrees(); |
0 |
| 6945 |
|
--- |
6945 |
|
--- |
| 6946 |
// TODO: Allow multi exit functions that have different free calls. |
--- |
6946 |
// TODO: Allow multi exit functions that have different free calls. |
--- |
| 6947 |
if (AI.PotentialFreeCalls.size() != 1) { |
0 |
6947 |
if (AI.PotentialFreeCalls.size() != 1) { |
0 |
| 6948 |
LLVM_DEBUG(dbgs() << "[H2S] did not find one free call but " |
0 |
6948 |
LLVM_DEBUG(dbgs() << "[H2S] did not find one free call but " |
0 |
| 6949 |
<< AI.PotentialFreeCalls.size() << "\n"); |
--- |
6949 |
<< AI.PotentialFreeCalls.size() << "\n"); |
--- |
| 6950 |
return false; |
0 |
6950 |
return false; |
0 |
| 6951 |
} |
--- |
6951 |
} |
--- |
| 6952 |
CallBase *UniqueFree = *AI.PotentialFreeCalls.begin(); |
0 |
6952 |
CallBase *UniqueFree = *AI.PotentialFreeCalls.begin(); |
0 |
| 6953 |
DeallocationInfo *DI = DeallocationInfos.lookup(UniqueFree); |
0 |
6953 |
DeallocationInfo *DI = DeallocationInfos.lookup(UniqueFree); |
0 |
| 6954 |
if (!DI) { |
0 |
6954 |
if (!DI) { |
0 |
| 6955 |
LLVM_DEBUG( |
0 |
6955 |
LLVM_DEBUG( |
0 |
| 6956 |
dbgs() << "[H2S] unique free call was not known as deallocation call " |
--- |
6956 |
dbgs() << "[H2S] unique free call was not known as deallocation call " |
--- |
| 6957 |
<< *UniqueFree << "\n"); |
--- |
6957 |
<< *UniqueFree << "\n"); |
--- |
| 6958 |
return false; |
0 |
6958 |
return false; |
0 |
| 6959 |
} |
--- |
6959 |
} |
--- |
| 6960 |
if (DI->MightFreeUnknownObjects) { |
0 |
6960 |
if (DI->MightFreeUnknownObjects) { |
0 |
| 6961 |
LLVM_DEBUG( |
0 |
6961 |
LLVM_DEBUG( |
0 |
| 6962 |
dbgs() << "[H2S] unique free call might free unknown allocations\n"); |
--- |
6962 |
dbgs() << "[H2S] unique free call might free unknown allocations\n"); |
--- |
| 6963 |
return false; |
0 |
6963 |
return false; |
0 |
| 6964 |
} |
--- |
6964 |
} |
--- |
| 6965 |
if (DI->PotentialAllocationCalls.empty()) |
0 |
6965 |
if (DI->PotentialAllocationCalls.empty()) |
0 |
| 6966 |
return true; |
0 |
6966 |
return true; |
0 |
| 6967 |
if (DI->PotentialAllocationCalls.size() > 1) { |
0 |
6967 |
if (DI->PotentialAllocationCalls.size() > 1) { |
0 |
| 6968 |
LLVM_DEBUG(dbgs() << "[H2S] unique free call might free " |
0 |
6968 |
LLVM_DEBUG(dbgs() << "[H2S] unique free call might free " |
0 |
| 6969 |
<< DI->PotentialAllocationCalls.size() |
--- |
6969 |
<< DI->PotentialAllocationCalls.size() |
--- |
| 6970 |
<< " different allocations\n"); |
--- |
6970 |
<< " different allocations\n"); |
--- |
| 6971 |
return false; |
0 |
6971 |
return false; |
0 |
| 6972 |
} |
--- |
6972 |
} |
--- |
| 6973 |
if (*DI->PotentialAllocationCalls.begin() != AI.CB) { |
0 |
6973 |
if (*DI->PotentialAllocationCalls.begin() != AI.CB) { |
0 |
| 6974 |
LLVM_DEBUG( |
0 |
6974 |
LLVM_DEBUG( |
0 |
| 6975 |
dbgs() |
--- |
6975 |
dbgs() |
--- |
| 6976 |
<< "[H2S] unique free call not known to free this allocation but " |
--- |
6976 |
<< "[H2S] unique free call not known to free this allocation but " |
--- |
| 6977 |
<< **DI->PotentialAllocationCalls.begin() << "\n"); |
--- |
6977 |
<< **DI->PotentialAllocationCalls.begin() << "\n"); |
--- |
| 6978 |
return false; |
0 |
6978 |
return false; |
0 |
| 6979 |
} |
--- |
6979 |
} |
--- |
| 6980 |
Instruction *CtxI = isa(AI.CB) ? AI.CB : AI.CB->getNextNode(); |
0 |
6980 |
Instruction *CtxI = isa(AI.CB) ? AI.CB : AI.CB->getNextNode(); |
0 |
| 6981 |
if (!Explorer || !Explorer->findInContextOf(UniqueFree, CtxI)) { |
0 |
6981 |
if (!Explorer || !Explorer->findInContextOf(UniqueFree, CtxI)) { |
0 |
| 6982 |
LLVM_DEBUG( |
0 |
6982 |
LLVM_DEBUG( |
0 |
| 6983 |
dbgs() |
--- |
6983 |
dbgs() |
--- |
| 6984 |
<< "[H2S] unique free call might not be executed with the allocation " |
--- |
6984 |
<< "[H2S] unique free call might not be executed with the allocation " |
--- |
| 6985 |
<< *UniqueFree << "\n"); |
--- |
6985 |
<< *UniqueFree << "\n"); |
--- |
| 6986 |
return false; |
0 |
6986 |
return false; |
0 |
| 6987 |
} |
--- |
6987 |
} |
--- |
| 6988 |
return true; |
0 |
6988 |
return true; |
0 |
| 6989 |
}; |
0 |
6989 |
}; |
0 |
| 6990 |
|
--- |
6990 |
|
--- |
| 6991 |
auto UsesCheck = [&](AllocationInfo &AI) { |
0 |
6991 |
auto UsesCheck = [&](AllocationInfo &AI) { |
0 |
| 6992 |
bool ValidUsesOnly = true; |
0 |
6992 |
bool ValidUsesOnly = true; |
0 |
| 6993 |
|
--- |
6993 |
|
--- |
| 6994 |
auto Pred = [&](const Use &U, bool &Follow) -> bool { |
0 |
6994 |
auto Pred = [&](const Use &U, bool &Follow) -> bool { |
0 |
| 6995 |
Instruction *UserI = cast(U.getUser()); |
0 |
6995 |
Instruction *UserI = cast(U.getUser()); |
0 |
| 6996 |
if (isa(UserI)) |
0 |
6996 |
if (isa(UserI)) |
0 |
| 6997 |
return true; |
0 |
6997 |
return true; |
0 |
| 6998 |
if (auto *SI = dyn_cast(UserI)) { |
0 |
6998 |
if (auto *SI = dyn_cast(UserI)) { |
0 |
| 6999 |
if (SI->getValueOperand() == U.get()) { |
0 |
6999 |
if (SI->getValueOperand() == U.get()) { |
0 |
| 7000 |
LLVM_DEBUG(dbgs() |
0 |
7000 |
LLVM_DEBUG(dbgs() |
0 |
| 7001 |
<< "[H2S] escaping store to memory: " << *UserI << "\n"); |
--- |
7001 |
<< "[H2S] escaping store to memory: " << *UserI << "\n"); |
--- |
| 7002 |
ValidUsesOnly = false; |
0 |
7002 |
ValidUsesOnly = false; |
0 |
| 7003 |
} else { |
--- |
7003 |
} else { |
--- |
| 7004 |
// A store into the malloc'ed memory is fine. |
--- |
7004 |
// A store into the malloc'ed memory is fine. |
--- |
| 7005 |
} |
--- |
7005 |
} |
--- |
| 7006 |
return true; |
0 |
7006 |
return true; |
0 |
| 7007 |
} |
--- |
7007 |
} |
--- |
| 7008 |
if (auto *CB = dyn_cast(UserI)) { |
0 |
7008 |
if (auto *CB = dyn_cast(UserI)) { |
0 |
| 7009 |
if (!CB->isArgOperand(&U) || CB->isLifetimeStartOrEnd()) |
0 |
7009 |
if (!CB->isArgOperand(&U) || CB->isLifetimeStartOrEnd()) |
0 |
| 7010 |
return true; |
0 |
7010 |
return true; |
0 |
| 7011 |
if (DeallocationInfos.count(CB)) { |
0 |
7011 |
if (DeallocationInfos.count(CB)) { |
0 |
| 7012 |
AI.PotentialFreeCalls.insert(CB); |
0 |
7012 |
AI.PotentialFreeCalls.insert(CB); |
0 |
| 7013 |
return true; |
0 |
7013 |
return true; |
0 |
| 7014 |
} |
--- |
7014 |
} |
--- |
| 7015 |
|
--- |
7015 |
|
--- |
| 7016 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
7016 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
| 7017 |
auto CBIRP = IRPosition::callsite_argument(*CB, ArgNo); |
0 |
7017 |
auto CBIRP = IRPosition::callsite_argument(*CB, ArgNo); |
0 |
| 7018 |
|
--- |
7018 |
|
--- |
| 7019 |
bool IsKnownNoCapture; |
--- |
7019 |
bool IsKnownNoCapture; |
--- |
| 7020 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
7020 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
| 7021 |
A, this, CBIRP, DepClassTy::OPTIONAL, IsKnownNoCapture); |
0 |
7021 |
A, this, CBIRP, DepClassTy::OPTIONAL, IsKnownNoCapture); |
0 |
| 7022 |
|
--- |
7022 |
|
--- |
| 7023 |
// If a call site argument use is nofree, we are fine. |
--- |
7023 |
// If a call site argument use is nofree, we are fine. |
--- |
| 7024 |
bool IsKnownNoFree; |
--- |
7024 |
bool IsKnownNoFree; |
--- |
| 7025 |
bool IsAssumedNoFree = AA::hasAssumedIRAttr( |
0 |
7025 |
bool IsAssumedNoFree = AA::hasAssumedIRAttr( |
0 |
| 7026 |
A, this, CBIRP, DepClassTy::OPTIONAL, IsKnownNoFree); |
--- |
7026 |
A, this, CBIRP, DepClassTy::OPTIONAL, IsKnownNoFree); |
--- |
| 7027 |
|
--- |
7027 |
|
--- |
| 7028 |
if (!IsAssumedNoCapture || |
0 |
7028 |
if (!IsAssumedNoCapture || |
0 |
| 7029 |
(AI.LibraryFunctionId != LibFunc___kmpc_alloc_shared && |
0 |
7029 |
(AI.LibraryFunctionId != LibFunc___kmpc_alloc_shared && |
0 |
| 7030 |
!IsAssumedNoFree)) { |
0 |
7030 |
!IsAssumedNoFree)) { |
0 |
| 7031 |
AI.HasPotentiallyFreeingUnknownUses |= !IsAssumedNoFree; |
0 |
7031 |
AI.HasPotentiallyFreeingUnknownUses |= !IsAssumedNoFree; |
0 |
| 7032 |
|
--- |
7032 |
|
--- |
| 7033 |
// Emit a missed remark if this is missed OpenMP globalization. |
--- |
7033 |
// Emit a missed remark if this is missed OpenMP globalization. |
--- |
| 7034 |
auto Remark = [&](OptimizationRemarkMissed ORM) { |
0 |
7034 |
auto Remark = [&](OptimizationRemarkMissed ORM) { |
0 |
| 7035 |
return ORM |
--- |
7035 |
return ORM |
--- |
| 7036 |
<< "Could not move globalized variable to the stack. " |
--- |
7036 |
<< "Could not move globalized variable to the stack. " |
--- |
| 7037 |
"Variable is potentially captured in call. Mark " |
--- |
7037 |
"Variable is potentially captured in call. Mark " |
--- |
| 7038 |
"parameter as `__attribute__((noescape))` to override."; |
0 |
7038 |
"parameter as `__attribute__((noescape))` to override."; |
0 |
| 7039 |
}; |
--- |
7039 |
}; |
--- |
| 7040 |
|
--- |
7040 |
|
--- |
| 7041 |
if (ValidUsesOnly && |
0 |
7041 |
if (ValidUsesOnly && |
0 |
| 7042 |
AI.LibraryFunctionId == LibFunc___kmpc_alloc_shared) |
0 |
7042 |
AI.LibraryFunctionId == LibFunc___kmpc_alloc_shared) |
0 |
| 7043 |
A.emitRemark(CB, "OMP113", Remark); |
0 |
7043 |
A.emitRemark(CB, "OMP113", Remark); |
0 |
| 7044 |
|
--- |
7044 |
|
--- |
| 7045 |
LLVM_DEBUG(dbgs() << "[H2S] Bad user: " << *UserI << "\n"); |
0 |
7045 |
LLVM_DEBUG(dbgs() << "[H2S] Bad user: " << *UserI << "\n"); |
0 |
| 7046 |
ValidUsesOnly = false; |
0 |
7046 |
ValidUsesOnly = false; |
0 |
| 7047 |
} |
--- |
7047 |
} |
--- |
| 7048 |
return true; |
0 |
7048 |
return true; |
0 |
| 7049 |
} |
--- |
7049 |
} |
--- |
| 7050 |
|
--- |
7050 |
|
--- |
| 7051 |
if (isa(UserI) || isa(UserI) || |
0 |
7051 |
if (isa(UserI) || isa(UserI) || |
0 |
| 7052 |
isa(UserI) || isa(UserI)) { |
0 |
7052 |
isa(UserI) || isa(UserI)) { |
0 |
| 7053 |
Follow = true; |
0 |
7053 |
Follow = true; |
0 |
| 7054 |
return true; |
0 |
7054 |
return true; |
0 |
| 7055 |
} |
--- |
7055 |
} |
--- |
| 7056 |
// Unknown user for which we can not track uses further (in a way that |
--- |
7056 |
// Unknown user for which we can not track uses further (in a way that |
--- |
| 7057 |
// makes sense). |
--- |
7057 |
// makes sense). |
--- |
| 7058 |
LLVM_DEBUG(dbgs() << "[H2S] Unknown user: " << *UserI << "\n"); |
0 |
7058 |
LLVM_DEBUG(dbgs() << "[H2S] Unknown user: " << *UserI << "\n"); |
0 |
| 7059 |
ValidUsesOnly = false; |
0 |
7059 |
ValidUsesOnly = false; |
0 |
| 7060 |
return true; |
0 |
7060 |
return true; |
0 |
| 7061 |
}; |
0 |
7061 |
}; |
0 |
| 7062 |
if (!A.checkForAllUses(Pred, *this, *AI.CB, /* CheckBBLivenessOnly */ false, |
0 |
7062 |
if (!A.checkForAllUses(Pred, *this, *AI.CB, /* CheckBBLivenessOnly */ false, |
0 |
| 7063 |
DepClassTy::OPTIONAL, /* IgnoreDroppableUses */ true, |
--- |
7063 |
DepClassTy::OPTIONAL, /* IgnoreDroppableUses */ true, |
--- |
| 7064 |
[&](const Use &OldU, const Use &NewU) { |
0 |
7064 |
[&](const Use &OldU, const Use &NewU) { |
0 |
| 7065 |
auto *SI = dyn_cast(OldU.getUser()); |
0 |
7065 |
auto *SI = dyn_cast(OldU.getUser()); |
0 |
| 7066 |
return !SI || StackIsAccessibleByOtherThreads || |
0 |
7066 |
return !SI || StackIsAccessibleByOtherThreads || |
0 |
| 7067 |
AA::isAssumedThreadLocalObject( |
0 |
7067 |
AA::isAssumedThreadLocalObject( |
0 |
| 7068 |
A, *SI->getPointerOperand(), *this); |
0 |
7068 |
A, *SI->getPointerOperand(), *this); |
0 |
| 7069 |
})) |
--- |
7069 |
})) |
--- |
| 7070 |
return false; |
0 |
7070 |
return false; |
0 |
| 7071 |
return ValidUsesOnly; |
0 |
7071 |
return ValidUsesOnly; |
0 |
| 7072 |
}; |
0 |
7072 |
}; |
0 |
| 7073 |
|
--- |
7073 |
|
--- |
| 7074 |
// The actual update starts here. We look at all allocations and depending on |
--- |
7074 |
// The actual update starts here. We look at all allocations and depending on |
--- |
| 7075 |
// their status perform the appropriate check(s). |
--- |
7075 |
// their status perform the appropriate check(s). |
--- |
| 7076 |
for (auto &It : AllocationInfos) { |
0 |
7076 |
for (auto &It : AllocationInfos) { |
0 |
| 7077 |
AllocationInfo &AI = *It.second; |
0 |
7077 |
AllocationInfo &AI = *It.second; |
0 |
| 7078 |
if (AI.Status == AllocationInfo::INVALID) |
0 |
7078 |
if (AI.Status == AllocationInfo::INVALID) |
0 |
| 7079 |
continue; |
0 |
7079 |
continue; |
0 |
| 7080 |
|
--- |
7080 |
|
--- |
| 7081 |
if (Value *Align = getAllocAlignment(AI.CB, TLI)) { |
0 |
7081 |
if (Value *Align = getAllocAlignment(AI.CB, TLI)) { |
0 |
| 7082 |
std::optional APAlign = getAPInt(A, *this, *Align); |
0 |
7082 |
std::optional APAlign = getAPInt(A, *this, *Align); |
0 |
| 7083 |
if (!APAlign) { |
0 |
7083 |
if (!APAlign) { |
0 |
| 7084 |
// Can't generate an alloca which respects the required alignment |
--- |
7084 |
// Can't generate an alloca which respects the required alignment |
--- |
| 7085 |
// on the allocation. |
--- |
7085 |
// on the allocation. |
--- |
| 7086 |
LLVM_DEBUG(dbgs() << "[H2S] Unknown allocation alignment: " << *AI.CB |
0 |
7086 |
LLVM_DEBUG(dbgs() << "[H2S] Unknown allocation alignment: " << *AI.CB |
0 |
| 7087 |
<< "\n"); |
--- |
7087 |
<< "\n"); |
--- |
| 7088 |
AI.Status = AllocationInfo::INVALID; |
0 |
7088 |
AI.Status = AllocationInfo::INVALID; |
0 |
| 7089 |
Changed = ChangeStatus::CHANGED; |
0 |
7089 |
Changed = ChangeStatus::CHANGED; |
0 |
| 7090 |
continue; |
0 |
7090 |
continue; |
0 |
| 7091 |
} |
--- |
7091 |
} |
--- |
| 7092 |
if (APAlign->ugt(llvm::Value::MaximumAlignment) || |
0 |
7092 |
if (APAlign->ugt(llvm::Value::MaximumAlignment) || |
0 |
| 7093 |
!APAlign->isPowerOf2()) { |
0 |
7093 |
!APAlign->isPowerOf2()) { |
0 |
| 7094 |
LLVM_DEBUG(dbgs() << "[H2S] Invalid allocation alignment: " << APAlign |
0 |
7094 |
LLVM_DEBUG(dbgs() << "[H2S] Invalid allocation alignment: " << APAlign |
0 |
| 7095 |
<< "\n"); |
--- |
7095 |
<< "\n"); |
--- |
| 7096 |
AI.Status = AllocationInfo::INVALID; |
0 |
7096 |
AI.Status = AllocationInfo::INVALID; |
0 |
| 7097 |
Changed = ChangeStatus::CHANGED; |
0 |
7097 |
Changed = ChangeStatus::CHANGED; |
0 |
| 7098 |
continue; |
0 |
7098 |
continue; |
0 |
| 7099 |
} |
--- |
7099 |
} |
--- |
| 7100 |
} |
0 |
7100 |
} |
0 |
| 7101 |
|
--- |
7101 |
|
--- |
| 7102 |
std::optional Size = getSize(A, *this, AI); |
0 |
7102 |
std::optional Size = getSize(A, *this, AI); |
0 |
| 7103 |
if (AI.LibraryFunctionId != LibFunc___kmpc_alloc_shared && |
0 |
7103 |
if (AI.LibraryFunctionId != LibFunc___kmpc_alloc_shared && |
0 |
| 7104 |
MaxHeapToStackSize != -1) { |
0 |
7104 |
MaxHeapToStackSize != -1) { |
0 |
| 7105 |
if (!Size || Size->ugt(MaxHeapToStackSize)) { |
0 |
7105 |
if (!Size || Size->ugt(MaxHeapToStackSize)) { |
0 |
| 7106 |
LLVM_DEBUG({ |
0 |
7106 |
LLVM_DEBUG({ |
0 |
| 7107 |
if (!Size) |
--- |
7107 |
if (!Size) |
--- |
| 7108 |
dbgs() << "[H2S] Unknown allocation size: " << *AI.CB << "\n"; |
--- |
7108 |
dbgs() << "[H2S] Unknown allocation size: " << *AI.CB << "\n"; |
--- |
| 7109 |
else |
--- |
7109 |
else |
--- |
| 7110 |
dbgs() << "[H2S] Allocation size too large: " << *AI.CB << " vs. " |
--- |
7110 |
dbgs() << "[H2S] Allocation size too large: " << *AI.CB << " vs. " |
--- |
| 7111 |
<< MaxHeapToStackSize << "\n"; |
--- |
7111 |
<< MaxHeapToStackSize << "\n"; |
--- |
| 7112 |
}); |
--- |
7112 |
}); |
--- |
| 7113 |
|
--- |
7113 |
|
--- |
| 7114 |
AI.Status = AllocationInfo::INVALID; |
0 |
7114 |
AI.Status = AllocationInfo::INVALID; |
0 |
| 7115 |
Changed = ChangeStatus::CHANGED; |
0 |
7115 |
Changed = ChangeStatus::CHANGED; |
0 |
| 7116 |
continue; |
0 |
7116 |
continue; |
0 |
| 7117 |
} |
--- |
7117 |
} |
--- |
| 7118 |
} |
--- |
7118 |
} |
--- |
| 7119 |
|
--- |
7119 |
|
--- |
| 7120 |
switch (AI.Status) { |
0 |
7120 |
switch (AI.Status) { |
0 |
| 7121 |
case AllocationInfo::STACK_DUE_TO_USE: |
0 |
7121 |
case AllocationInfo::STACK_DUE_TO_USE: |
0 |
| 7122 |
if (UsesCheck(AI)) |
0 |
7122 |
if (UsesCheck(AI)) |
0 |
| 7123 |
break; |
0 |
7123 |
break; |
0 |
| 7124 |
AI.Status = AllocationInfo::STACK_DUE_TO_FREE; |
0 |
7124 |
AI.Status = AllocationInfo::STACK_DUE_TO_FREE; |
0 |
| 7125 |
[[fallthrough]]; |
--- |
7125 |
[[fallthrough]]; |
--- |
| 7126 |
case AllocationInfo::STACK_DUE_TO_FREE: |
0 |
7126 |
case AllocationInfo::STACK_DUE_TO_FREE: |
0 |
| 7127 |
if (FreeCheck(AI)) |
0 |
7127 |
if (FreeCheck(AI)) |
0 |
| 7128 |
break; |
0 |
7128 |
break; |
0 |
| 7129 |
AI.Status = AllocationInfo::INVALID; |
0 |
7129 |
AI.Status = AllocationInfo::INVALID; |
0 |
| 7130 |
Changed = ChangeStatus::CHANGED; |
0 |
7130 |
Changed = ChangeStatus::CHANGED; |
0 |
| 7131 |
break; |
0 |
7131 |
break; |
0 |
| 7132 |
case AllocationInfo::INVALID: |
0 |
7132 |
case AllocationInfo::INVALID: |
0 |
| 7133 |
llvm_unreachable("Invalid allocations should never reach this point!"); |
0 |
7133 |
llvm_unreachable("Invalid allocations should never reach this point!"); |
0 |
| 7134 |
}; |
--- |
7134 |
}; |
--- |
| 7135 |
|
--- |
7135 |
|
--- |
| 7136 |
// Check if we still think we can move it into the entry block. If the |
--- |
7136 |
// Check if we still think we can move it into the entry block. If the |
--- |
| 7137 |
// alloca comes from a converted __kmpc_alloc_shared then we can usually |
--- |
7137 |
// alloca comes from a converted __kmpc_alloc_shared then we can usually |
--- |
| 7138 |
// ignore the potential compilations associated with loops. |
--- |
7138 |
// ignore the potential compilations associated with loops. |
--- |
| 7139 |
bool IsGlobalizedLocal = |
0 |
7139 |
bool IsGlobalizedLocal = |
0 |
| 7140 |
AI.LibraryFunctionId == LibFunc___kmpc_alloc_shared; |
0 |
7140 |
AI.LibraryFunctionId == LibFunc___kmpc_alloc_shared; |
0 |
| 7141 |
if (AI.MoveAllocaIntoEntry && |
0 |
7141 |
if (AI.MoveAllocaIntoEntry && |
0 |
| 7142 |
(!Size.has_value() || |
0 |
7142 |
(!Size.has_value() || |
0 |
| 7143 |
(!IsGlobalizedLocal && IsInLoop(*AI.CB->getParent())))) |
0 |
7143 |
(!IsGlobalizedLocal && IsInLoop(*AI.CB->getParent())))) |
0 |
| 7144 |
AI.MoveAllocaIntoEntry = false; |
0 |
7144 |
AI.MoveAllocaIntoEntry = false; |
0 |
| 7145 |
} |
0 |
7145 |
} |
0 |
| 7146 |
|
--- |
7146 |
|
--- |
| 7147 |
return Changed; |
0 |
7147 |
return Changed; |
0 |
| 7148 |
} |
--- |
7148 |
} |
--- |
| 7149 |
} // namespace |
--- |
7149 |
} // namespace |
--- |
| 7150 |
|
--- |
7150 |
|
--- |
| 7151 |
/// ----------------------- Privatizable Pointers ------------------------------ |
--- |
7151 |
/// ----------------------- Privatizable Pointers ------------------------------ |
--- |
| 7152 |
namespace { |
--- |
7152 |
namespace { |
--- |
| 7153 |
struct AAPrivatizablePtrImpl : public AAPrivatizablePtr { |
--- |
7153 |
struct AAPrivatizablePtrImpl : public AAPrivatizablePtr { |
--- |
| 7154 |
AAPrivatizablePtrImpl(const IRPosition &IRP, Attributor &A) |
0 |
7154 |
AAPrivatizablePtrImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 7155 |
: AAPrivatizablePtr(IRP, A), PrivatizableType(std::nullopt) {} |
0 |
7155 |
: AAPrivatizablePtr(IRP, A), PrivatizableType(std::nullopt) {} |
0 |
| 7156 |
|
--- |
7156 |
|
--- |
| 7157 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
7157 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
| 7158 |
AAPrivatizablePtr::indicatePessimisticFixpoint(); |
0 |
7158 |
AAPrivatizablePtr::indicatePessimisticFixpoint(); |
0 |
| 7159 |
PrivatizableType = nullptr; |
0 |
7159 |
PrivatizableType = nullptr; |
0 |
| 7160 |
return ChangeStatus::CHANGED; |
0 |
7160 |
return ChangeStatus::CHANGED; |
0 |
| 7161 |
} |
--- |
7161 |
} |
--- |
| 7162 |
|
--- |
7162 |
|
--- |
| 7163 |
/// Identify the type we can chose for a private copy of the underlying |
--- |
7163 |
/// Identify the type we can chose for a private copy of the underlying |
--- |
| 7164 |
/// argument. std::nullopt means it is not clear yet, nullptr means there is |
--- |
7164 |
/// argument. std::nullopt means it is not clear yet, nullptr means there is |
--- |
| 7165 |
/// none. |
--- |
7165 |
/// none. |
--- |
| 7166 |
virtual std::optional identifyPrivatizableType(Attributor &A) = 0; |
--- |
7166 |
virtual std::optional identifyPrivatizableType(Attributor &A) = 0; |
--- |
| 7167 |
|
--- |
7167 |
|
--- |
| 7168 |
/// Return a privatizable type that encloses both T0 and T1. |
--- |
7168 |
/// Return a privatizable type that encloses both T0 and T1. |
--- |
| 7169 |
/// TODO: This is merely a stub for now as we should manage a mapping as well. |
--- |
7169 |
/// TODO: This is merely a stub for now as we should manage a mapping as well. |
--- |
| 7170 |
std::optional combineTypes(std::optional T0, |
0 |
7170 |
std::optional combineTypes(std::optional T0, |
0 |
| 7171 |
std::optional T1) { |
--- |
7171 |
std::optional T1) { |
--- |
| 7172 |
if (!T0) |
0 |
7172 |
if (!T0) |
0 |
| 7173 |
return T1; |
0 |
7173 |
return T1; |
0 |
| 7174 |
if (!T1) |
0 |
7174 |
if (!T1) |
0 |
| 7175 |
return T0; |
0 |
7175 |
return T0; |
0 |
| 7176 |
if (T0 == T1) |
0 |
7176 |
if (T0 == T1) |
0 |
| 7177 |
return T0; |
0 |
7177 |
return T0; |
0 |
| 7178 |
return nullptr; |
0 |
7178 |
return nullptr; |
0 |
| 7179 |
} |
--- |
7179 |
} |
--- |
| 7180 |
|
--- |
7180 |
|
--- |
| 7181 |
std::optional getPrivatizableType() const override { |
0 |
7181 |
std::optional getPrivatizableType() const override { |
0 |
| 7182 |
return PrivatizableType; |
0 |
7182 |
return PrivatizableType; |
0 |
| 7183 |
} |
--- |
7183 |
} |
--- |
| 7184 |
|
--- |
7184 |
|
--- |
| 7185 |
const std::string getAsStr(Attributor *A) const override { |
0 |
7185 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 7186 |
return isAssumedPrivatizablePtr() ? "[priv]" : "[no-priv]"; |
0 |
7186 |
return isAssumedPrivatizablePtr() ? "[priv]" : "[no-priv]"; |
0 |
| 7187 |
} |
--- |
7187 |
} |
--- |
| 7188 |
|
--- |
7188 |
|
--- |
| 7189 |
protected: |
--- |
7189 |
protected: |
--- |
| 7190 |
std::optional PrivatizableType; |
--- |
7190 |
std::optional PrivatizableType; |
--- |
| 7191 |
}; |
--- |
7191 |
}; |
--- |
| 7192 |
|
--- |
7192 |
|
--- |
| 7193 |
// TODO: Do this for call site arguments (probably also other values) as well. |
--- |
7193 |
// TODO: Do this for call site arguments (probably also other values) as well. |
--- |
| 7194 |
|
--- |
7194 |
|
--- |
| 7195 |
struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl { |
--- |
7195 |
struct AAPrivatizablePtrArgument final : public AAPrivatizablePtrImpl { |
--- |
| 7196 |
AAPrivatizablePtrArgument(const IRPosition &IRP, Attributor &A) |
0 |
7196 |
AAPrivatizablePtrArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 7197 |
: AAPrivatizablePtrImpl(IRP, A) {} |
0 |
7197 |
: AAPrivatizablePtrImpl(IRP, A) {} |
0 |
| 7198 |
|
--- |
7198 |
|
--- |
| 7199 |
/// See AAPrivatizablePtrImpl::identifyPrivatizableType(...) |
--- |
7199 |
/// See AAPrivatizablePtrImpl::identifyPrivatizableType(...) |
--- |
| 7200 |
std::optional identifyPrivatizableType(Attributor &A) override { |
0 |
7200 |
std::optional identifyPrivatizableType(Attributor &A) override { |
0 |
| 7201 |
// If this is a byval argument and we know all the call sites (so we can |
--- |
7201 |
// If this is a byval argument and we know all the call sites (so we can |
--- |
| 7202 |
// rewrite them), there is no need to check them explicitly. |
--- |
7202 |
// rewrite them), there is no need to check them explicitly. |
--- |
| 7203 |
bool UsedAssumedInformation = false; |
0 |
7203 |
bool UsedAssumedInformation = false; |
0 |
| 7204 |
SmallVector Attrs; |
0 |
7204 |
SmallVector Attrs; |
0 |
| 7205 |
A.getAttrs(getIRPosition(), {Attribute::ByVal}, Attrs, |
0 |
7205 |
A.getAttrs(getIRPosition(), {Attribute::ByVal}, Attrs, |
0 |
| 7206 |
/* IgnoreSubsumingPositions */ true); |
--- |
7206 |
/* IgnoreSubsumingPositions */ true); |
--- |
| 7207 |
if (!Attrs.empty() && |
0 |
7207 |
if (!Attrs.empty() && |
0 |
| 7208 |
A.checkForAllCallSites([](AbstractCallSite ACS) { return true; }, *this, |
0 |
7208 |
A.checkForAllCallSites([](AbstractCallSite ACS) { return true; }, *this, |
0 |
| 7209 |
true, UsedAssumedInformation)) |
--- |
7209 |
true, UsedAssumedInformation)) |
--- |
| 7210 |
return Attrs[0].getValueAsType(); |
0 |
7210 |
return Attrs[0].getValueAsType(); |
0 |
| 7211 |
|
--- |
7211 |
|
--- |
| 7212 |
std::optional Ty; |
0 |
7212 |
std::optional Ty; |
0 |
| 7213 |
unsigned ArgNo = getIRPosition().getCallSiteArgNo(); |
0 |
7213 |
unsigned ArgNo = getIRPosition().getCallSiteArgNo(); |
0 |
| 7214 |
|
--- |
7214 |
|
--- |
| 7215 |
// Make sure the associated call site argument has the same type at all call |
--- |
7215 |
// Make sure the associated call site argument has the same type at all call |
--- |
| 7216 |
// sites and it is an allocation we know is safe to privatize, for now that |
--- |
7216 |
// sites and it is an allocation we know is safe to privatize, for now that |
--- |
| 7217 |
// means we only allow alloca instructions. |
--- |
7217 |
// means we only allow alloca instructions. |
--- |
| 7218 |
// TODO: We can additionally analyze the accesses in the callee to create |
--- |
7218 |
// TODO: We can additionally analyze the accesses in the callee to create |
--- |
| 7219 |
// the type from that information instead. That is a little more |
--- |
7219 |
// the type from that information instead. That is a little more |
--- |
| 7220 |
// involved and will be done in a follow up patch. |
--- |
7220 |
// involved and will be done in a follow up patch. |
--- |
| 7221 |
auto CallSiteCheck = [&](AbstractCallSite ACS) { |
0 |
7221 |
auto CallSiteCheck = [&](AbstractCallSite ACS) { |
0 |
| 7222 |
IRPosition ACSArgPos = IRPosition::callsite_argument(ACS, ArgNo); |
0 |
7222 |
IRPosition ACSArgPos = IRPosition::callsite_argument(ACS, ArgNo); |
0 |
| 7223 |
// Check if a coresponding argument was found or if it is one not |
--- |
7223 |
// Check if a coresponding argument was found or if it is one not |
--- |
| 7224 |
// associated (which can happen for callback calls). |
--- |
7224 |
// associated (which can happen for callback calls). |
--- |
| 7225 |
if (ACSArgPos.getPositionKind() == IRPosition::IRP_INVALID) |
0 |
7225 |
if (ACSArgPos.getPositionKind() == IRPosition::IRP_INVALID) |
0 |
| 7226 |
return false; |
0 |
7226 |
return false; |
0 |
| 7227 |
|
--- |
7227 |
|
--- |
| 7228 |
// Check that all call sites agree on a type. |
--- |
7228 |
// Check that all call sites agree on a type. |
--- |
| 7229 |
auto *PrivCSArgAA = |
--- |
7229 |
auto *PrivCSArgAA = |
--- |
| 7230 |
A.getAAFor(*this, ACSArgPos, DepClassTy::REQUIRED); |
0 |
7230 |
A.getAAFor(*this, ACSArgPos, DepClassTy::REQUIRED); |
0 |
| 7231 |
if (!PrivCSArgAA) |
0 |
7231 |
if (!PrivCSArgAA) |
0 |
| 7232 |
return false; |
0 |
7232 |
return false; |
0 |
| 7233 |
std::optional CSTy = PrivCSArgAA->getPrivatizableType(); |
0 |
7233 |
std::optional CSTy = PrivCSArgAA->getPrivatizableType(); |
0 |
| 7234 |
|
--- |
7234 |
|
--- |
| 7235 |
LLVM_DEBUG({ |
0 |
7235 |
LLVM_DEBUG({ |
0 |
| 7236 |
dbgs() << "[AAPrivatizablePtr] ACSPos: " << ACSArgPos << ", CSTy: "; |
--- |
7236 |
dbgs() << "[AAPrivatizablePtr] ACSPos: " << ACSArgPos << ", CSTy: "; |
--- |
| 7237 |
if (CSTy && *CSTy) |
--- |
7237 |
if (CSTy && *CSTy) |
--- |
| 7238 |
(*CSTy)->print(dbgs()); |
--- |
7238 |
(*CSTy)->print(dbgs()); |
--- |
| 7239 |
else if (CSTy) |
--- |
7239 |
else if (CSTy) |
--- |
| 7240 |
dbgs() << ""; |
--- |
7240 |
dbgs() << ""; |
--- |
| 7241 |
else |
--- |
7241 |
else |
--- |
| 7242 |
dbgs() << ""; |
--- |
7242 |
dbgs() << ""; |
--- |
| 7243 |
}); |
--- |
7243 |
}); |
--- |
| 7244 |
|
--- |
7244 |
|
--- |
| 7245 |
Ty = combineTypes(Ty, CSTy); |
0 |
7245 |
Ty = combineTypes(Ty, CSTy); |
0 |
| 7246 |
|
--- |
7246 |
|
--- |
| 7247 |
LLVM_DEBUG({ |
0 |
7247 |
LLVM_DEBUG({ |
0 |
| 7248 |
dbgs() << " : New Type: "; |
--- |
7248 |
dbgs() << " : New Type: "; |
--- |
| 7249 |
if (Ty && *Ty) |
--- |
7249 |
if (Ty && *Ty) |
--- |
| 7250 |
(*Ty)->print(dbgs()); |
--- |
7250 |
(*Ty)->print(dbgs()); |
--- |
| 7251 |
else if (Ty) |
--- |
7251 |
else if (Ty) |
--- |
| 7252 |
dbgs() << ""; |
--- |
7252 |
dbgs() << ""; |
--- |
| 7253 |
else |
--- |
7253 |
else |
--- |
| 7254 |
dbgs() << ""; |
--- |
7254 |
dbgs() << ""; |
--- |
| 7255 |
dbgs() << "\n"; |
--- |
7255 |
dbgs() << "\n"; |
--- |
| 7256 |
}); |
--- |
7256 |
}); |
--- |
| 7257 |
|
--- |
7257 |
|
--- |
| 7258 |
return !Ty || *Ty; |
0 |
7258 |
return !Ty || *Ty; |
0 |
| 7259 |
}; |
0 |
7259 |
}; |
0 |
| 7260 |
|
--- |
7260 |
|
--- |
| 7261 |
if (!A.checkForAllCallSites(CallSiteCheck, *this, true, |
0 |
7261 |
if (!A.checkForAllCallSites(CallSiteCheck, *this, true, |
0 |
| 7262 |
UsedAssumedInformation)) |
--- |
7262 |
UsedAssumedInformation)) |
--- |
| 7263 |
return nullptr; |
0 |
7263 |
return nullptr; |
0 |
| 7264 |
return Ty; |
0 |
7264 |
return Ty; |
0 |
| 7265 |
} |
0 |
7265 |
} |
0 |
| 7266 |
|
--- |
7266 |
|
--- |
| 7267 |
/// See AbstractAttribute::updateImpl(...). |
--- |
7267 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 7268 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
7268 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 7269 |
PrivatizableType = identifyPrivatizableType(A); |
0 |
7269 |
PrivatizableType = identifyPrivatizableType(A); |
0 |
| 7270 |
if (!PrivatizableType) |
0 |
7270 |
if (!PrivatizableType) |
0 |
| 7271 |
return ChangeStatus::UNCHANGED; |
0 |
7271 |
return ChangeStatus::UNCHANGED; |
0 |
| 7272 |
if (!*PrivatizableType) |
0 |
7272 |
if (!*PrivatizableType) |
0 |
| 7273 |
return indicatePessimisticFixpoint(); |
0 |
7273 |
return indicatePessimisticFixpoint(); |
0 |
| 7274 |
|
--- |
7274 |
|
--- |
| 7275 |
// The dependence is optional so we don't give up once we give up on the |
--- |
7275 |
// The dependence is optional so we don't give up once we give up on the |
--- |
| 7276 |
// alignment. |
--- |
7276 |
// alignment. |
--- |
| 7277 |
A.getAAFor(*this, IRPosition::value(getAssociatedValue()), |
0 |
7277 |
A.getAAFor(*this, IRPosition::value(getAssociatedValue()), |
0 |
| 7278 |
DepClassTy::OPTIONAL); |
--- |
7278 |
DepClassTy::OPTIONAL); |
--- |
| 7279 |
|
--- |
7279 |
|
--- |
| 7280 |
// Avoid arguments with padding for now. |
--- |
7280 |
// Avoid arguments with padding for now. |
--- |
| 7281 |
if (!A.hasAttr(getIRPosition(), Attribute::ByVal) && |
0 |
7281 |
if (!A.hasAttr(getIRPosition(), Attribute::ByVal) && |
0 |
| 7282 |
!isDenselyPacked(*PrivatizableType, A.getInfoCache().getDL())) { |
0 |
7282 |
!isDenselyPacked(*PrivatizableType, A.getInfoCache().getDL())) { |
0 |
| 7283 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] Padding detected\n"); |
0 |
7283 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] Padding detected\n"); |
0 |
| 7284 |
return indicatePessimisticFixpoint(); |
0 |
7284 |
return indicatePessimisticFixpoint(); |
0 |
| 7285 |
} |
--- |
7285 |
} |
--- |
| 7286 |
|
--- |
7286 |
|
--- |
| 7287 |
// Collect the types that will replace the privatizable type in the function |
--- |
7287 |
// Collect the types that will replace the privatizable type in the function |
--- |
| 7288 |
// signature. |
--- |
7288 |
// signature. |
--- |
| 7289 |
SmallVector ReplacementTypes; |
0 |
7289 |
SmallVector ReplacementTypes; |
0 |
| 7290 |
identifyReplacementTypes(*PrivatizableType, ReplacementTypes); |
0 |
7290 |
identifyReplacementTypes(*PrivatizableType, ReplacementTypes); |
0 |
| 7291 |
|
--- |
7291 |
|
--- |
| 7292 |
// Verify callee and caller agree on how the promoted argument would be |
--- |
7292 |
// Verify callee and caller agree on how the promoted argument would be |
--- |
| 7293 |
// passed. |
--- |
7293 |
// passed. |
--- |
| 7294 |
Function &Fn = *getIRPosition().getAnchorScope(); |
0 |
7294 |
Function &Fn = *getIRPosition().getAnchorScope(); |
0 |
| 7295 |
const auto *TTI = |
--- |
7295 |
const auto *TTI = |
--- |
| 7296 |
A.getInfoCache().getAnalysisResultForFunction(Fn); |
0 |
7296 |
A.getInfoCache().getAnalysisResultForFunction(Fn); |
0 |
| 7297 |
if (!TTI) { |
0 |
7297 |
if (!TTI) { |
0 |
| 7298 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] Missing TTI for function " |
0 |
7298 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] Missing TTI for function " |
0 |
| 7299 |
<< Fn.getName() << "\n"); |
--- |
7299 |
<< Fn.getName() << "\n"); |
--- |
| 7300 |
return indicatePessimisticFixpoint(); |
0 |
7300 |
return indicatePessimisticFixpoint(); |
0 |
| 7301 |
} |
--- |
7301 |
} |
--- |
| 7302 |
|
--- |
7302 |
|
--- |
| 7303 |
auto CallSiteCheck = [&](AbstractCallSite ACS) { |
0 |
7303 |
auto CallSiteCheck = [&](AbstractCallSite ACS) { |
0 |
| 7304 |
CallBase *CB = ACS.getInstruction(); |
0 |
7304 |
CallBase *CB = ACS.getInstruction(); |
0 |
| 7305 |
return TTI->areTypesABICompatible( |
0 |
7305 |
return TTI->areTypesABICompatible( |
0 |
| 7306 |
CB->getCaller(), |
0 |
7306 |
CB->getCaller(), |
0 |
| 7307 |
dyn_cast_if_present(CB->getCalledOperand()), |
0 |
7307 |
dyn_cast_if_present(CB->getCalledOperand()), |
0 |
| 7308 |
ReplacementTypes); |
0 |
7308 |
ReplacementTypes); |
0 |
| 7309 |
}; |
0 |
7309 |
}; |
0 |
| 7310 |
bool UsedAssumedInformation = false; |
0 |
7310 |
bool UsedAssumedInformation = false; |
0 |
| 7311 |
if (!A.checkForAllCallSites(CallSiteCheck, *this, true, |
0 |
7311 |
if (!A.checkForAllCallSites(CallSiteCheck, *this, true, |
0 |
| 7312 |
UsedAssumedInformation)) { |
--- |
7312 |
UsedAssumedInformation)) { |
--- |
| 7313 |
LLVM_DEBUG( |
0 |
7313 |
LLVM_DEBUG( |
0 |
| 7314 |
dbgs() << "[AAPrivatizablePtr] ABI incompatibility detected for " |
--- |
7314 |
dbgs() << "[AAPrivatizablePtr] ABI incompatibility detected for " |
--- |
| 7315 |
<< Fn.getName() << "\n"); |
--- |
7315 |
<< Fn.getName() << "\n"); |
--- |
| 7316 |
return indicatePessimisticFixpoint(); |
0 |
7316 |
return indicatePessimisticFixpoint(); |
0 |
| 7317 |
} |
--- |
7317 |
} |
--- |
| 7318 |
|
--- |
7318 |
|
--- |
| 7319 |
// Register a rewrite of the argument. |
--- |
7319 |
// Register a rewrite of the argument. |
--- |
| 7320 |
Argument *Arg = getAssociatedArgument(); |
0 |
7320 |
Argument *Arg = getAssociatedArgument(); |
0 |
| 7321 |
if (!A.isValidFunctionSignatureRewrite(*Arg, ReplacementTypes)) { |
0 |
7321 |
if (!A.isValidFunctionSignatureRewrite(*Arg, ReplacementTypes)) { |
0 |
| 7322 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] Rewrite not valid\n"); |
0 |
7322 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] Rewrite not valid\n"); |
0 |
| 7323 |
return indicatePessimisticFixpoint(); |
0 |
7323 |
return indicatePessimisticFixpoint(); |
0 |
| 7324 |
} |
--- |
7324 |
} |
--- |
| 7325 |
|
--- |
7325 |
|
--- |
| 7326 |
unsigned ArgNo = Arg->getArgNo(); |
0 |
7326 |
unsigned ArgNo = Arg->getArgNo(); |
0 |
| 7327 |
|
--- |
7327 |
|
--- |
| 7328 |
// Helper to check if for the given call site the associated argument is |
--- |
7328 |
// Helper to check if for the given call site the associated argument is |
--- |
| 7329 |
// passed to a callback where the privatization would be different. |
--- |
7329 |
// passed to a callback where the privatization would be different. |
--- |
| 7330 |
auto IsCompatiblePrivArgOfCallback = [&](CallBase &CB) { |
0 |
7330 |
auto IsCompatiblePrivArgOfCallback = [&](CallBase &CB) { |
0 |
| 7331 |
SmallVector CallbackUses; |
0 |
7331 |
SmallVector CallbackUses; |
0 |
| 7332 |
AbstractCallSite::getCallbackUses(CB, CallbackUses); |
0 |
7332 |
AbstractCallSite::getCallbackUses(CB, CallbackUses); |
0 |
| 7333 |
for (const Use *U : CallbackUses) { |
0 |
7333 |
for (const Use *U : CallbackUses) { |
0 |
| 7334 |
AbstractCallSite CBACS(U); |
0 |
7334 |
AbstractCallSite CBACS(U); |
0 |
| 7335 |
assert(CBACS && CBACS.isCallbackCall()); |
0 |
7335 |
assert(CBACS && CBACS.isCallbackCall()); |
0 |
| 7336 |
for (Argument &CBArg : CBACS.getCalledFunction()->args()) { |
0 |
7336 |
for (Argument &CBArg : CBACS.getCalledFunction()->args()) { |
0 |
| 7337 |
int CBArgNo = CBACS.getCallArgOperandNo(CBArg); |
0 |
7337 |
int CBArgNo = CBACS.getCallArgOperandNo(CBArg); |
0 |
| 7338 |
|
--- |
7338 |
|
--- |
| 7339 |
LLVM_DEBUG({ |
0 |
7339 |
LLVM_DEBUG({ |
0 |
| 7340 |
dbgs() |
--- |
7340 |
dbgs() |
--- |
| 7341 |
<< "[AAPrivatizablePtr] Argument " << *Arg |
--- |
7341 |
<< "[AAPrivatizablePtr] Argument " << *Arg |
--- |
| 7342 |
<< "check if can be privatized in the context of its parent (" |
--- |
7342 |
<< "check if can be privatized in the context of its parent (" |
--- |
| 7343 |
<< Arg->getParent()->getName() |
--- |
7343 |
<< Arg->getParent()->getName() |
--- |
| 7344 |
<< ")\n[AAPrivatizablePtr] because it is an argument in a " |
--- |
7344 |
<< ")\n[AAPrivatizablePtr] because it is an argument in a " |
--- |
| 7345 |
"callback (" |
--- |
7345 |
"callback (" |
--- |
| 7346 |
<< CBArgNo << "@" << CBACS.getCalledFunction()->getName() |
--- |
7346 |
<< CBArgNo << "@" << CBACS.getCalledFunction()->getName() |
--- |
| 7347 |
<< ")\n[AAPrivatizablePtr] " << CBArg << " : " |
--- |
7347 |
<< ")\n[AAPrivatizablePtr] " << CBArg << " : " |
--- |
| 7348 |
<< CBACS.getCallArgOperand(CBArg) << " vs " |
--- |
7348 |
<< CBACS.getCallArgOperand(CBArg) << " vs " |
--- |
| 7349 |
<< CB.getArgOperand(ArgNo) << "\n" |
--- |
7349 |
<< CB.getArgOperand(ArgNo) << "\n" |
--- |
| 7350 |
<< "[AAPrivatizablePtr] " << CBArg << " : " |
--- |
7350 |
<< "[AAPrivatizablePtr] " << CBArg << " : " |
--- |
| 7351 |
<< CBACS.getCallArgOperandNo(CBArg) << " vs " << ArgNo << "\n"; |
--- |
7351 |
<< CBACS.getCallArgOperandNo(CBArg) << " vs " << ArgNo << "\n"; |
--- |
| 7352 |
}); |
--- |
7352 |
}); |
--- |
| 7353 |
|
--- |
7353 |
|
--- |
| 7354 |
if (CBArgNo != int(ArgNo)) |
0 |
7354 |
if (CBArgNo != int(ArgNo)) |
0 |
| 7355 |
continue; |
0 |
7355 |
continue; |
0 |
| 7356 |
const auto *CBArgPrivAA = A.getAAFor( |
0 |
7356 |
const auto *CBArgPrivAA = A.getAAFor( |
0 |
| 7357 |
*this, IRPosition::argument(CBArg), DepClassTy::REQUIRED); |
0 |
7357 |
*this, IRPosition::argument(CBArg), DepClassTy::REQUIRED); |
0 |
| 7358 |
if (CBArgPrivAA && CBArgPrivAA->isValidState()) { |
0 |
7358 |
if (CBArgPrivAA && CBArgPrivAA->isValidState()) { |
0 |
| 7359 |
auto CBArgPrivTy = CBArgPrivAA->getPrivatizableType(); |
0 |
7359 |
auto CBArgPrivTy = CBArgPrivAA->getPrivatizableType(); |
0 |
| 7360 |
if (!CBArgPrivTy) |
0 |
7360 |
if (!CBArgPrivTy) |
0 |
| 7361 |
continue; |
0 |
7361 |
continue; |
0 |
| 7362 |
if (*CBArgPrivTy == PrivatizableType) |
0 |
7362 |
if (*CBArgPrivTy == PrivatizableType) |
0 |
| 7363 |
continue; |
0 |
7363 |
continue; |
0 |
| 7364 |
} |
--- |
7364 |
} |
--- |
| 7365 |
|
--- |
7365 |
|
--- |
| 7366 |
LLVM_DEBUG({ |
0 |
7366 |
LLVM_DEBUG({ |
0 |
| 7367 |
dbgs() << "[AAPrivatizablePtr] Argument " << *Arg |
--- |
7367 |
dbgs() << "[AAPrivatizablePtr] Argument " << *Arg |
--- |
| 7368 |
<< " cannot be privatized in the context of its parent (" |
--- |
7368 |
<< " cannot be privatized in the context of its parent (" |
--- |
| 7369 |
<< Arg->getParent()->getName() |
--- |
7369 |
<< Arg->getParent()->getName() |
--- |
| 7370 |
<< ")\n[AAPrivatizablePtr] because it is an argument in a " |
--- |
7370 |
<< ")\n[AAPrivatizablePtr] because it is an argument in a " |
--- |
| 7371 |
"callback (" |
--- |
7371 |
"callback (" |
--- |
| 7372 |
<< CBArgNo << "@" << CBACS.getCalledFunction()->getName() |
--- |
7372 |
<< CBArgNo << "@" << CBACS.getCalledFunction()->getName() |
--- |
| 7373 |
<< ").\n[AAPrivatizablePtr] for which the argument " |
--- |
7373 |
<< ").\n[AAPrivatizablePtr] for which the argument " |
--- |
| 7374 |
"privatization is not compatible.\n"; |
--- |
7374 |
"privatization is not compatible.\n"; |
--- |
| 7375 |
}); |
--- |
7375 |
}); |
--- |
| 7376 |
return false; |
0 |
7376 |
return false; |
0 |
| 7377 |
} |
--- |
7377 |
} |
--- |
| 7378 |
} |
0 |
7378 |
} |
0 |
| 7379 |
return true; |
0 |
7379 |
return true; |
0 |
| 7380 |
}; |
0 |
7380 |
}; |
0 |
| 7381 |
|
--- |
7381 |
|
--- |
| 7382 |
// Helper to check if for the given call site the associated argument is |
--- |
7382 |
// Helper to check if for the given call site the associated argument is |
--- |
| 7383 |
// passed to a direct call where the privatization would be different. |
--- |
7383 |
// passed to a direct call where the privatization would be different. |
--- |
| 7384 |
auto IsCompatiblePrivArgOfDirectCS = [&](AbstractCallSite ACS) { |
0 |
7384 |
auto IsCompatiblePrivArgOfDirectCS = [&](AbstractCallSite ACS) { |
0 |
| 7385 |
CallBase *DC = cast(ACS.getInstruction()); |
0 |
7385 |
CallBase *DC = cast(ACS.getInstruction()); |
0 |
| 7386 |
int DCArgNo = ACS.getCallArgOperandNo(ArgNo); |
0 |
7386 |
int DCArgNo = ACS.getCallArgOperandNo(ArgNo); |
0 |
| 7387 |
assert(DCArgNo >= 0 && unsigned(DCArgNo) < DC->arg_size() && |
0 |
7387 |
assert(DCArgNo >= 0 && unsigned(DCArgNo) < DC->arg_size() && |
0 |
| 7388 |
"Expected a direct call operand for callback call operand"); |
--- |
7388 |
"Expected a direct call operand for callback call operand"); |
--- |
| 7389 |
|
--- |
7389 |
|
--- |
| 7390 |
Function *DCCallee = |
--- |
7390 |
Function *DCCallee = |
--- |
| 7391 |
dyn_cast_if_present(DC->getCalledOperand()); |
0 |
7391 |
dyn_cast_if_present(DC->getCalledOperand()); |
0 |
| 7392 |
LLVM_DEBUG({ |
0 |
7392 |
LLVM_DEBUG({ |
0 |
| 7393 |
dbgs() << "[AAPrivatizablePtr] Argument " << *Arg |
--- |
7393 |
dbgs() << "[AAPrivatizablePtr] Argument " << *Arg |
--- |
| 7394 |
<< " check if be privatized in the context of its parent (" |
--- |
7394 |
<< " check if be privatized in the context of its parent (" |
--- |
| 7395 |
<< Arg->getParent()->getName() |
--- |
7395 |
<< Arg->getParent()->getName() |
--- |
| 7396 |
<< ")\n[AAPrivatizablePtr] because it is an argument in a " |
--- |
7396 |
<< ")\n[AAPrivatizablePtr] because it is an argument in a " |
--- |
| 7397 |
"direct call of (" |
--- |
7397 |
"direct call of (" |
--- |
| 7398 |
<< DCArgNo << "@" << DCCallee->getName() << ").\n"; |
--- |
7398 |
<< DCArgNo << "@" << DCCallee->getName() << ").\n"; |
--- |
| 7399 |
}); |
--- |
7399 |
}); |
--- |
| 7400 |
|
--- |
7400 |
|
--- |
| 7401 |
if (unsigned(DCArgNo) < DCCallee->arg_size()) { |
0 |
7401 |
if (unsigned(DCArgNo) < DCCallee->arg_size()) { |
0 |
| 7402 |
const auto *DCArgPrivAA = A.getAAFor( |
0 |
7402 |
const auto *DCArgPrivAA = A.getAAFor( |
0 |
| 7403 |
*this, IRPosition::argument(*DCCallee->getArg(DCArgNo)), |
0 |
7403 |
*this, IRPosition::argument(*DCCallee->getArg(DCArgNo)), |
0 |
| 7404 |
DepClassTy::REQUIRED); |
--- |
7404 |
DepClassTy::REQUIRED); |
--- |
| 7405 |
if (DCArgPrivAA && DCArgPrivAA->isValidState()) { |
0 |
7405 |
if (DCArgPrivAA && DCArgPrivAA->isValidState()) { |
0 |
| 7406 |
auto DCArgPrivTy = DCArgPrivAA->getPrivatizableType(); |
0 |
7406 |
auto DCArgPrivTy = DCArgPrivAA->getPrivatizableType(); |
0 |
| 7407 |
if (!DCArgPrivTy) |
0 |
7407 |
if (!DCArgPrivTy) |
0 |
| 7408 |
return true; |
0 |
7408 |
return true; |
0 |
| 7409 |
if (*DCArgPrivTy == PrivatizableType) |
0 |
7409 |
if (*DCArgPrivTy == PrivatizableType) |
0 |
| 7410 |
return true; |
0 |
7410 |
return true; |
0 |
| 7411 |
} |
--- |
7411 |
} |
--- |
| 7412 |
} |
--- |
7412 |
} |
--- |
| 7413 |
|
--- |
7413 |
|
--- |
| 7414 |
LLVM_DEBUG({ |
0 |
7414 |
LLVM_DEBUG({ |
0 |
| 7415 |
dbgs() << "[AAPrivatizablePtr] Argument " << *Arg |
--- |
7415 |
dbgs() << "[AAPrivatizablePtr] Argument " << *Arg |
--- |
| 7416 |
<< " cannot be privatized in the context of its parent (" |
--- |
7416 |
<< " cannot be privatized in the context of its parent (" |
--- |
| 7417 |
<< Arg->getParent()->getName() |
--- |
7417 |
<< Arg->getParent()->getName() |
--- |
| 7418 |
<< ")\n[AAPrivatizablePtr] because it is an argument in a " |
--- |
7418 |
<< ")\n[AAPrivatizablePtr] because it is an argument in a " |
--- |
| 7419 |
"direct call of (" |
--- |
7419 |
"direct call of (" |
--- |
| 7420 |
<< ACS.getInstruction()->getCalledOperand()->getName() |
--- |
7420 |
<< ACS.getInstruction()->getCalledOperand()->getName() |
--- |
| 7421 |
<< ").\n[AAPrivatizablePtr] for which the argument " |
--- |
7421 |
<< ").\n[AAPrivatizablePtr] for which the argument " |
--- |
| 7422 |
"privatization is not compatible.\n"; |
--- |
7422 |
"privatization is not compatible.\n"; |
--- |
| 7423 |
}); |
--- |
7423 |
}); |
--- |
| 7424 |
return false; |
0 |
7424 |
return false; |
0 |
| 7425 |
}; |
0 |
7425 |
}; |
0 |
| 7426 |
|
--- |
7426 |
|
--- |
| 7427 |
// Helper to check if the associated argument is used at the given abstract |
--- |
7427 |
// Helper to check if the associated argument is used at the given abstract |
--- |
| 7428 |
// call site in a way that is incompatible with the privatization assumed |
--- |
7428 |
// call site in a way that is incompatible with the privatization assumed |
--- |
| 7429 |
// here. |
--- |
7429 |
// here. |
--- |
| 7430 |
auto IsCompatiblePrivArgOfOtherCallSite = [&](AbstractCallSite ACS) { |
0 |
7430 |
auto IsCompatiblePrivArgOfOtherCallSite = [&](AbstractCallSite ACS) { |
0 |
| 7431 |
if (ACS.isDirectCall()) |
0 |
7431 |
if (ACS.isDirectCall()) |
0 |
| 7432 |
return IsCompatiblePrivArgOfCallback(*ACS.getInstruction()); |
0 |
7432 |
return IsCompatiblePrivArgOfCallback(*ACS.getInstruction()); |
0 |
| 7433 |
if (ACS.isCallbackCall()) |
0 |
7433 |
if (ACS.isCallbackCall()) |
0 |
| 7434 |
return IsCompatiblePrivArgOfDirectCS(ACS); |
0 |
7434 |
return IsCompatiblePrivArgOfDirectCS(ACS); |
0 |
| 7435 |
return false; |
0 |
7435 |
return false; |
0 |
| 7436 |
}; |
0 |
7436 |
}; |
0 |
| 7437 |
|
--- |
7437 |
|
--- |
| 7438 |
if (!A.checkForAllCallSites(IsCompatiblePrivArgOfOtherCallSite, *this, true, |
0 |
7438 |
if (!A.checkForAllCallSites(IsCompatiblePrivArgOfOtherCallSite, *this, true, |
0 |
| 7439 |
UsedAssumedInformation)) |
--- |
7439 |
UsedAssumedInformation)) |
--- |
| 7440 |
return indicatePessimisticFixpoint(); |
0 |
7440 |
return indicatePessimisticFixpoint(); |
0 |
| 7441 |
|
--- |
7441 |
|
--- |
| 7442 |
return ChangeStatus::UNCHANGED; |
0 |
7442 |
return ChangeStatus::UNCHANGED; |
0 |
| 7443 |
} |
0 |
7443 |
} |
0 |
| 7444 |
|
--- |
7444 |
|
--- |
| 7445 |
/// Given a type to private \p PrivType, collect the constituates (which are |
--- |
7445 |
/// Given a type to private \p PrivType, collect the constituates (which are |
--- |
| 7446 |
/// used) in \p ReplacementTypes. |
--- |
7446 |
/// used) in \p ReplacementTypes. |
--- |
| 7447 |
static void |
--- |
7447 |
static void |
--- |
| 7448 |
identifyReplacementTypes(Type *PrivType, |
0 |
7448 |
identifyReplacementTypes(Type *PrivType, |
0 |
| 7449 |
SmallVectorImpl &ReplacementTypes) { |
--- |
7449 |
SmallVectorImpl &ReplacementTypes) { |
--- |
| 7450 |
// TODO: For now we expand the privatization type to the fullest which can |
--- |
7450 |
// TODO: For now we expand the privatization type to the fullest which can |
--- |
| 7451 |
// lead to dead arguments that need to be removed later. |
--- |
7451 |
// lead to dead arguments that need to be removed later. |
--- |
| 7452 |
assert(PrivType && "Expected privatizable type!"); |
0 |
7452 |
assert(PrivType && "Expected privatizable type!"); |
0 |
| 7453 |
|
--- |
7453 |
|
--- |
| 7454 |
// Traverse the type, extract constituate types on the outermost level. |
--- |
7454 |
// Traverse the type, extract constituate types on the outermost level. |
--- |
| 7455 |
if (auto *PrivStructType = dyn_cast(PrivType)) { |
0 |
7455 |
if (auto *PrivStructType = dyn_cast(PrivType)) { |
0 |
| 7456 |
for (unsigned u = 0, e = PrivStructType->getNumElements(); u < e; u++) |
0 |
7456 |
for (unsigned u = 0, e = PrivStructType->getNumElements(); u < e; u++) |
0 |
| 7457 |
ReplacementTypes.push_back(PrivStructType->getElementType(u)); |
0 |
7457 |
ReplacementTypes.push_back(PrivStructType->getElementType(u)); |
0 |
| 7458 |
} else if (auto *PrivArrayType = dyn_cast(PrivType)) { |
0 |
7458 |
} else if (auto *PrivArrayType = dyn_cast(PrivType)) { |
0 |
| 7459 |
ReplacementTypes.append(PrivArrayType->getNumElements(), |
0 |
7459 |
ReplacementTypes.append(PrivArrayType->getNumElements(), |
0 |
| 7460 |
PrivArrayType->getElementType()); |
--- |
7460 |
PrivArrayType->getElementType()); |
--- |
| 7461 |
} else { |
--- |
7461 |
} else { |
--- |
| 7462 |
ReplacementTypes.push_back(PrivType); |
0 |
7462 |
ReplacementTypes.push_back(PrivType); |
0 |
| 7463 |
} |
--- |
7463 |
} |
--- |
| 7464 |
} |
0 |
7464 |
} |
0 |
| 7465 |
|
--- |
7465 |
|
--- |
| 7466 |
/// Initialize \p Base according to the type \p PrivType at position \p IP. |
--- |
7466 |
/// Initialize \p Base according to the type \p PrivType at position \p IP. |
--- |
| 7467 |
/// The values needed are taken from the arguments of \p F starting at |
--- |
7467 |
/// The values needed are taken from the arguments of \p F starting at |
--- |
| 7468 |
/// position \p ArgNo. |
--- |
7468 |
/// position \p ArgNo. |
--- |
| 7469 |
static void createInitialization(Type *PrivType, Value &Base, Function &F, |
0 |
7469 |
static void createInitialization(Type *PrivType, Value &Base, Function &F, |
0 |
| 7470 |
unsigned ArgNo, Instruction &IP) { |
--- |
7470 |
unsigned ArgNo, Instruction &IP) { |
--- |
| 7471 |
assert(PrivType && "Expected privatizable type!"); |
0 |
7471 |
assert(PrivType && "Expected privatizable type!"); |
0 |
| 7472 |
|
--- |
7472 |
|
--- |
| 7473 |
IRBuilder IRB(&IP); |
0 |
7473 |
IRBuilder IRB(&IP); |
0 |
| 7474 |
const DataLayout &DL = F.getParent()->getDataLayout(); |
0 |
7474 |
const DataLayout &DL = F.getParent()->getDataLayout(); |
0 |
| 7475 |
|
--- |
7475 |
|
--- |
| 7476 |
// Traverse the type, build GEPs and stores. |
--- |
7476 |
// Traverse the type, build GEPs and stores. |
--- |
| 7477 |
if (auto *PrivStructType = dyn_cast(PrivType)) { |
0 |
7477 |
if (auto *PrivStructType = dyn_cast(PrivType)) { |
0 |
| 7478 |
const StructLayout *PrivStructLayout = DL.getStructLayout(PrivStructType); |
0 |
7478 |
const StructLayout *PrivStructLayout = DL.getStructLayout(PrivStructType); |
0 |
| 7479 |
for (unsigned u = 0, e = PrivStructType->getNumElements(); u < e; u++) { |
0 |
7479 |
for (unsigned u = 0, e = PrivStructType->getNumElements(); u < e; u++) { |
0 |
| 7480 |
Type *PointeeTy = PrivStructType->getElementType(u)->getPointerTo(); |
0 |
7480 |
Type *PointeeTy = PrivStructType->getElementType(u)->getPointerTo(); |
0 |
| 7481 |
Value *Ptr = |
--- |
7481 |
Value *Ptr = |
--- |
| 7482 |
constructPointer(PointeeTy, PrivType, &Base, |
0 |
7482 |
constructPointer(PointeeTy, PrivType, &Base, |
0 |
| 7483 |
PrivStructLayout->getElementOffset(u), IRB, DL); |
0 |
7483 |
PrivStructLayout->getElementOffset(u), IRB, DL); |
0 |
| 7484 |
new StoreInst(F.getArg(ArgNo + u), Ptr, &IP); |
0 |
7484 |
new StoreInst(F.getArg(ArgNo + u), Ptr, &IP); |
0 |
| 7485 |
} |
--- |
7485 |
} |
--- |
| 7486 |
} else if (auto *PrivArrayType = dyn_cast(PrivType)) { |
0 |
7486 |
} else if (auto *PrivArrayType = dyn_cast(PrivType)) { |
0 |
| 7487 |
Type *PointeeTy = PrivArrayType->getElementType(); |
0 |
7487 |
Type *PointeeTy = PrivArrayType->getElementType(); |
0 |
| 7488 |
Type *PointeePtrTy = PointeeTy->getPointerTo(); |
0 |
7488 |
Type *PointeePtrTy = PointeeTy->getPointerTo(); |
0 |
| 7489 |
uint64_t PointeeTySize = DL.getTypeStoreSize(PointeeTy); |
0 |
7489 |
uint64_t PointeeTySize = DL.getTypeStoreSize(PointeeTy); |
0 |
| 7490 |
for (unsigned u = 0, e = PrivArrayType->getNumElements(); u < e; u++) { |
0 |
7490 |
for (unsigned u = 0, e = PrivArrayType->getNumElements(); u < e; u++) { |
0 |
| 7491 |
Value *Ptr = constructPointer(PointeePtrTy, PrivType, &Base, |
0 |
7491 |
Value *Ptr = constructPointer(PointeePtrTy, PrivType, &Base, |
0 |
| 7492 |
u * PointeeTySize, IRB, DL); |
0 |
7492 |
u * PointeeTySize, IRB, DL); |
0 |
| 7493 |
new StoreInst(F.getArg(ArgNo + u), Ptr, &IP); |
0 |
7493 |
new StoreInst(F.getArg(ArgNo + u), Ptr, &IP); |
0 |
| 7494 |
} |
--- |
7494 |
} |
--- |
| 7495 |
} else { |
--- |
7495 |
} else { |
--- |
| 7496 |
new StoreInst(F.getArg(ArgNo), &Base, &IP); |
0 |
7496 |
new StoreInst(F.getArg(ArgNo), &Base, &IP); |
0 |
| 7497 |
} |
--- |
7497 |
} |
--- |
| 7498 |
} |
0 |
7498 |
} |
0 |
| 7499 |
|
--- |
7499 |
|
--- |
| 7500 |
/// Extract values from \p Base according to the type \p PrivType at the |
--- |
7500 |
/// Extract values from \p Base according to the type \p PrivType at the |
--- |
| 7501 |
/// call position \p ACS. The values are appended to \p ReplacementValues. |
--- |
7501 |
/// call position \p ACS. The values are appended to \p ReplacementValues. |
--- |
| 7502 |
void createReplacementValues(Align Alignment, Type *PrivType, |
0 |
7502 |
void createReplacementValues(Align Alignment, Type *PrivType, |
0 |
| 7503 |
AbstractCallSite ACS, Value *Base, |
--- |
7503 |
AbstractCallSite ACS, Value *Base, |
--- |
| 7504 |
SmallVectorImpl &ReplacementValues) { |
--- |
7504 |
SmallVectorImpl &ReplacementValues) { |
--- |
| 7505 |
assert(Base && "Expected base value!"); |
0 |
7505 |
assert(Base && "Expected base value!"); |
0 |
| 7506 |
assert(PrivType && "Expected privatizable type!"); |
0 |
7506 |
assert(PrivType && "Expected privatizable type!"); |
0 |
| 7507 |
Instruction *IP = ACS.getInstruction(); |
0 |
7507 |
Instruction *IP = ACS.getInstruction(); |
0 |
| 7508 |
|
--- |
7508 |
|
--- |
| 7509 |
IRBuilder IRB(IP); |
0 |
7509 |
IRBuilder IRB(IP); |
0 |
| 7510 |
const DataLayout &DL = IP->getModule()->getDataLayout(); |
0 |
7510 |
const DataLayout &DL = IP->getModule()->getDataLayout(); |
0 |
| 7511 |
|
--- |
7511 |
|
--- |
| 7512 |
Type *PrivPtrType = PrivType->getPointerTo(); |
0 |
7512 |
Type *PrivPtrType = PrivType->getPointerTo(); |
0 |
| 7513 |
if (Base->getType() != PrivPtrType) |
0 |
7513 |
if (Base->getType() != PrivPtrType) |
0 |
| 7514 |
Base = BitCastInst::CreatePointerBitCastOrAddrSpaceCast( |
0 |
7514 |
Base = BitCastInst::CreatePointerBitCastOrAddrSpaceCast( |
0 |
| 7515 |
Base, PrivPtrType, "", ACS.getInstruction()); |
0 |
7515 |
Base, PrivPtrType, "", ACS.getInstruction()); |
0 |
| 7516 |
|
--- |
7516 |
|
--- |
| 7517 |
// Traverse the type, build GEPs and loads. |
--- |
7517 |
// Traverse the type, build GEPs and loads. |
--- |
| 7518 |
if (auto *PrivStructType = dyn_cast(PrivType)) { |
0 |
7518 |
if (auto *PrivStructType = dyn_cast(PrivType)) { |
0 |
| 7519 |
const StructLayout *PrivStructLayout = DL.getStructLayout(PrivStructType); |
0 |
7519 |
const StructLayout *PrivStructLayout = DL.getStructLayout(PrivStructType); |
0 |
| 7520 |
for (unsigned u = 0, e = PrivStructType->getNumElements(); u < e; u++) { |
0 |
7520 |
for (unsigned u = 0, e = PrivStructType->getNumElements(); u < e; u++) { |
0 |
| 7521 |
Type *PointeeTy = PrivStructType->getElementType(u); |
0 |
7521 |
Type *PointeeTy = PrivStructType->getElementType(u); |
0 |
| 7522 |
Value *Ptr = |
--- |
7522 |
Value *Ptr = |
--- |
| 7523 |
constructPointer(PointeeTy->getPointerTo(), PrivType, Base, |
0 |
7523 |
constructPointer(PointeeTy->getPointerTo(), PrivType, Base, |
0 |
| 7524 |
PrivStructLayout->getElementOffset(u), IRB, DL); |
0 |
7524 |
PrivStructLayout->getElementOffset(u), IRB, DL); |
0 |
| 7525 |
LoadInst *L = new LoadInst(PointeeTy, Ptr, "", IP); |
0 |
7525 |
LoadInst *L = new LoadInst(PointeeTy, Ptr, "", IP); |
0 |
| 7526 |
L->setAlignment(Alignment); |
0 |
7526 |
L->setAlignment(Alignment); |
0 |
| 7527 |
ReplacementValues.push_back(L); |
0 |
7527 |
ReplacementValues.push_back(L); |
0 |
| 7528 |
} |
--- |
7528 |
} |
--- |
| 7529 |
} else if (auto *PrivArrayType = dyn_cast(PrivType)) { |
0 |
7529 |
} else if (auto *PrivArrayType = dyn_cast(PrivType)) { |
0 |
| 7530 |
Type *PointeeTy = PrivArrayType->getElementType(); |
0 |
7530 |
Type *PointeeTy = PrivArrayType->getElementType(); |
0 |
| 7531 |
uint64_t PointeeTySize = DL.getTypeStoreSize(PointeeTy); |
0 |
7531 |
uint64_t PointeeTySize = DL.getTypeStoreSize(PointeeTy); |
0 |
| 7532 |
Type *PointeePtrTy = PointeeTy->getPointerTo(); |
0 |
7532 |
Type *PointeePtrTy = PointeeTy->getPointerTo(); |
0 |
| 7533 |
for (unsigned u = 0, e = PrivArrayType->getNumElements(); u < e; u++) { |
0 |
7533 |
for (unsigned u = 0, e = PrivArrayType->getNumElements(); u < e; u++) { |
0 |
| 7534 |
Value *Ptr = constructPointer(PointeePtrTy, PrivType, Base, |
0 |
7534 |
Value *Ptr = constructPointer(PointeePtrTy, PrivType, Base, |
0 |
| 7535 |
u * PointeeTySize, IRB, DL); |
0 |
7535 |
u * PointeeTySize, IRB, DL); |
0 |
| 7536 |
LoadInst *L = new LoadInst(PointeeTy, Ptr, "", IP); |
0 |
7536 |
LoadInst *L = new LoadInst(PointeeTy, Ptr, "", IP); |
0 |
| 7537 |
L->setAlignment(Alignment); |
0 |
7537 |
L->setAlignment(Alignment); |
0 |
| 7538 |
ReplacementValues.push_back(L); |
0 |
7538 |
ReplacementValues.push_back(L); |
0 |
| 7539 |
} |
--- |
7539 |
} |
--- |
| 7540 |
} else { |
--- |
7540 |
} else { |
--- |
| 7541 |
LoadInst *L = new LoadInst(PrivType, Base, "", IP); |
0 |
7541 |
LoadInst *L = new LoadInst(PrivType, Base, "", IP); |
0 |
| 7542 |
L->setAlignment(Alignment); |
0 |
7542 |
L->setAlignment(Alignment); |
0 |
| 7543 |
ReplacementValues.push_back(L); |
0 |
7543 |
ReplacementValues.push_back(L); |
0 |
| 7544 |
} |
--- |
7544 |
} |
--- |
| 7545 |
} |
0 |
7545 |
} |
0 |
| 7546 |
|
--- |
7546 |
|
--- |
| 7547 |
/// See AbstractAttribute::manifest(...) |
--- |
7547 |
/// See AbstractAttribute::manifest(...) |
--- |
| 7548 |
ChangeStatus manifest(Attributor &A) override { |
0 |
7548 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 7549 |
if (!PrivatizableType) |
0 |
7549 |
if (!PrivatizableType) |
0 |
| 7550 |
return ChangeStatus::UNCHANGED; |
0 |
7550 |
return ChangeStatus::UNCHANGED; |
0 |
| 7551 |
assert(*PrivatizableType && "Expected privatizable type!"); |
0 |
7551 |
assert(*PrivatizableType && "Expected privatizable type!"); |
0 |
| 7552 |
|
--- |
7552 |
|
--- |
| 7553 |
// Collect all tail calls in the function as we cannot allow new allocas to |
--- |
7553 |
// Collect all tail calls in the function as we cannot allow new allocas to |
--- |
| 7554 |
// escape into tail recursion. |
--- |
7554 |
// escape into tail recursion. |
--- |
| 7555 |
// TODO: Be smarter about new allocas escaping into tail calls. |
--- |
7555 |
// TODO: Be smarter about new allocas escaping into tail calls. |
--- |
| 7556 |
SmallVector TailCalls; |
0 |
7556 |
SmallVector TailCalls; |
0 |
| 7557 |
bool UsedAssumedInformation = false; |
0 |
7557 |
bool UsedAssumedInformation = false; |
0 |
| 7558 |
if (!A.checkForAllInstructions( |
0 |
7558 |
if (!A.checkForAllInstructions( |
0 |
| 7559 |
[&](Instruction &I) { |
0 |
7559 |
[&](Instruction &I) { |
0 |
| 7560 |
CallInst &CI = cast(I); |
0 |
7560 |
CallInst &CI = cast(I); |
0 |
| 7561 |
if (CI.isTailCall()) |
0 |
7561 |
if (CI.isTailCall()) |
0 |
| 7562 |
TailCalls.push_back(&CI); |
0 |
7562 |
TailCalls.push_back(&CI); |
0 |
| 7563 |
return true; |
0 |
7563 |
return true; |
0 |
| 7564 |
}, |
--- |
7564 |
}, |
--- |
| 7565 |
*this, {Instruction::Call}, UsedAssumedInformation)) |
--- |
7565 |
*this, {Instruction::Call}, UsedAssumedInformation)) |
--- |
| 7566 |
return ChangeStatus::UNCHANGED; |
0 |
7566 |
return ChangeStatus::UNCHANGED; |
0 |
| 7567 |
|
--- |
7567 |
|
--- |
| 7568 |
Argument *Arg = getAssociatedArgument(); |
0 |
7568 |
Argument *Arg = getAssociatedArgument(); |
0 |
| 7569 |
// Query AAAlign attribute for alignment of associated argument to |
--- |
7569 |
// Query AAAlign attribute for alignment of associated argument to |
--- |
| 7570 |
// determine the best alignment of loads. |
--- |
7570 |
// determine the best alignment of loads. |
--- |
| 7571 |
const auto *AlignAA = |
--- |
7571 |
const auto *AlignAA = |
--- |
| 7572 |
A.getAAFor(*this, IRPosition::value(*Arg), DepClassTy::NONE); |
0 |
7572 |
A.getAAFor(*this, IRPosition::value(*Arg), DepClassTy::NONE); |
0 |
| 7573 |
|
--- |
7573 |
|
--- |
| 7574 |
// Callback to repair the associated function. A new alloca is placed at the |
--- |
7574 |
// Callback to repair the associated function. A new alloca is placed at the |
--- |
| 7575 |
// beginning and initialized with the values passed through arguments. The |
--- |
7575 |
// beginning and initialized with the values passed through arguments. The |
--- |
| 7576 |
// new alloca replaces the use of the old pointer argument. |
--- |
7576 |
// new alloca replaces the use of the old pointer argument. |
--- |
| 7577 |
Attributor::ArgumentReplacementInfo::CalleeRepairCBTy FnRepairCB = |
--- |
7577 |
Attributor::ArgumentReplacementInfo::CalleeRepairCBTy FnRepairCB = |
--- |
| 7578 |
[=](const Attributor::ArgumentReplacementInfo &ARI, |
0 |
7578 |
[=](const Attributor::ArgumentReplacementInfo &ARI, |
0 |
| 7579 |
Function &ReplacementFn, Function::arg_iterator ArgIt) { |
--- |
7579 |
Function &ReplacementFn, Function::arg_iterator ArgIt) { |
--- |
| 7580 |
BasicBlock &EntryBB = ReplacementFn.getEntryBlock(); |
0 |
7580 |
BasicBlock &EntryBB = ReplacementFn.getEntryBlock(); |
0 |
| 7581 |
Instruction *IP = &*EntryBB.getFirstInsertionPt(); |
0 |
7581 |
Instruction *IP = &*EntryBB.getFirstInsertionPt(); |
0 |
| 7582 |
const DataLayout &DL = IP->getModule()->getDataLayout(); |
0 |
7582 |
const DataLayout &DL = IP->getModule()->getDataLayout(); |
0 |
| 7583 |
unsigned AS = DL.getAllocaAddrSpace(); |
0 |
7583 |
unsigned AS = DL.getAllocaAddrSpace(); |
0 |
| 7584 |
Instruction *AI = new AllocaInst(*PrivatizableType, AS, |
0 |
7584 |
Instruction *AI = new AllocaInst(*PrivatizableType, AS, |
0 |
| 7585 |
Arg->getName() + ".priv", IP); |
0 |
7585 |
Arg->getName() + ".priv", IP); |
0 |
| 7586 |
createInitialization(*PrivatizableType, *AI, ReplacementFn, |
0 |
7586 |
createInitialization(*PrivatizableType, *AI, ReplacementFn, |
0 |
| 7587 |
ArgIt->getArgNo(), *IP); |
--- |
7587 |
ArgIt->getArgNo(), *IP); |
--- |
| 7588 |
|
--- |
7588 |
|
--- |
| 7589 |
if (AI->getType() != Arg->getType()) |
0 |
7589 |
if (AI->getType() != Arg->getType()) |
0 |
| 7590 |
AI = BitCastInst::CreatePointerBitCastOrAddrSpaceCast( |
0 |
7590 |
AI = BitCastInst::CreatePointerBitCastOrAddrSpaceCast( |
0 |
| 7591 |
AI, Arg->getType(), "", IP); |
--- |
7591 |
AI, Arg->getType(), "", IP); |
--- |
| 7592 |
Arg->replaceAllUsesWith(AI); |
0 |
7592 |
Arg->replaceAllUsesWith(AI); |
0 |
| 7593 |
|
--- |
7593 |
|
--- |
| 7594 |
for (CallInst *CI : TailCalls) |
0 |
7594 |
for (CallInst *CI : TailCalls) |
0 |
| 7595 |
CI->setTailCall(false); |
0 |
7595 |
CI->setTailCall(false); |
0 |
| 7596 |
}; |
0 |
7596 |
}; |
0 |
| 7597 |
|
--- |
7597 |
|
--- |
| 7598 |
// Callback to repair a call site of the associated function. The elements |
--- |
7598 |
// Callback to repair a call site of the associated function. The elements |
--- |
| 7599 |
// of the privatizable type are loaded prior to the call and passed to the |
--- |
7599 |
// of the privatizable type are loaded prior to the call and passed to the |
--- |
| 7600 |
// new function version. |
--- |
7600 |
// new function version. |
--- |
| 7601 |
Attributor::ArgumentReplacementInfo::ACSRepairCBTy ACSRepairCB = |
--- |
7601 |
Attributor::ArgumentReplacementInfo::ACSRepairCBTy ACSRepairCB = |
--- |
| 7602 |
[=](const Attributor::ArgumentReplacementInfo &ARI, |
0 |
7602 |
[=](const Attributor::ArgumentReplacementInfo &ARI, |
0 |
| 7603 |
AbstractCallSite ACS, SmallVectorImpl &NewArgOperands) { |
--- |
7603 |
AbstractCallSite ACS, SmallVectorImpl &NewArgOperands) { |
--- |
| 7604 |
// When no alignment is specified for the load instruction, |
--- |
7604 |
// When no alignment is specified for the load instruction, |
--- |
| 7605 |
// natural alignment is assumed. |
--- |
7605 |
// natural alignment is assumed. |
--- |
| 7606 |
createReplacementValues( |
0 |
7606 |
createReplacementValues( |
0 |
| 7607 |
AlignAA ? AlignAA->getAssumedAlign() : Align(0), |
0 |
7607 |
AlignAA ? AlignAA->getAssumedAlign() : Align(0), |
0 |
| 7608 |
*PrivatizableType, ACS, |
0 |
7608 |
*PrivatizableType, ACS, |
0 |
| 7609 |
ACS.getCallArgOperand(ARI.getReplacedArg().getArgNo()), |
0 |
7609 |
ACS.getCallArgOperand(ARI.getReplacedArg().getArgNo()), |
0 |
| 7610 |
NewArgOperands); |
--- |
7610 |
NewArgOperands); |
--- |
| 7611 |
}; |
0 |
7611 |
}; |
0 |
| 7612 |
|
--- |
7612 |
|
--- |
| 7613 |
// Collect the types that will replace the privatizable type in the function |
--- |
7613 |
// Collect the types that will replace the privatizable type in the function |
--- |
| 7614 |
// signature. |
--- |
7614 |
// signature. |
--- |
| 7615 |
SmallVector ReplacementTypes; |
0 |
7615 |
SmallVector ReplacementTypes; |
0 |
| 7616 |
identifyReplacementTypes(*PrivatizableType, ReplacementTypes); |
0 |
7616 |
identifyReplacementTypes(*PrivatizableType, ReplacementTypes); |
0 |
| 7617 |
|
--- |
7617 |
|
--- |
| 7618 |
// Register a rewrite of the argument. |
--- |
7618 |
// Register a rewrite of the argument. |
--- |
| 7619 |
if (A.registerFunctionSignatureRewrite(*Arg, ReplacementTypes, |
0 |
7619 |
if (A.registerFunctionSignatureRewrite(*Arg, ReplacementTypes, |
0 |
| 7620 |
std::move(FnRepairCB), |
0 |
7620 |
std::move(FnRepairCB), |
0 |
| 7621 |
std::move(ACSRepairCB))) |
0 |
7621 |
std::move(ACSRepairCB))) |
0 |
| 7622 |
return ChangeStatus::CHANGED; |
0 |
7622 |
return ChangeStatus::CHANGED; |
0 |
| 7623 |
return ChangeStatus::UNCHANGED; |
0 |
7623 |
return ChangeStatus::UNCHANGED; |
0 |
| 7624 |
} |
0 |
7624 |
} |
0 |
| 7625 |
|
--- |
7625 |
|
--- |
| 7626 |
/// See AbstractAttribute::trackStatistics() |
--- |
7626 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 7627 |
void trackStatistics() const override { |
0 |
7627 |
void trackStatistics() const override { |
0 |
| 7628 |
STATS_DECLTRACK_ARG_ATTR(privatizable_ptr); |
0 |
7628 |
STATS_DECLTRACK_ARG_ATTR(privatizable_ptr); |
0 |
| 7629 |
} |
0 |
7629 |
} |
0 |
| 7630 |
}; |
--- |
7630 |
}; |
--- |
| 7631 |
|
--- |
7631 |
|
--- |
| 7632 |
struct AAPrivatizablePtrFloating : public AAPrivatizablePtrImpl { |
--- |
7632 |
struct AAPrivatizablePtrFloating : public AAPrivatizablePtrImpl { |
--- |
| 7633 |
AAPrivatizablePtrFloating(const IRPosition &IRP, Attributor &A) |
0 |
7633 |
AAPrivatizablePtrFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 7634 |
: AAPrivatizablePtrImpl(IRP, A) {} |
0 |
7634 |
: AAPrivatizablePtrImpl(IRP, A) {} |
0 |
| 7635 |
|
--- |
7635 |
|
--- |
| 7636 |
/// See AbstractAttribute::initialize(...). |
--- |
7636 |
/// See AbstractAttribute::initialize(...). |
--- |
| 7637 |
void initialize(Attributor &A) override { |
0 |
7637 |
void initialize(Attributor &A) override { |
0 |
| 7638 |
// TODO: We can privatize more than arguments. |
--- |
7638 |
// TODO: We can privatize more than arguments. |
--- |
| 7639 |
indicatePessimisticFixpoint(); |
0 |
7639 |
indicatePessimisticFixpoint(); |
0 |
| 7640 |
} |
0 |
7640 |
} |
0 |
| 7641 |
|
--- |
7641 |
|
--- |
| 7642 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
7642 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 7643 |
llvm_unreachable("AAPrivatizablePtr(Floating|Returned|CallSiteReturned)::" |
0 |
7643 |
llvm_unreachable("AAPrivatizablePtr(Floating|Returned|CallSiteReturned)::" |
0 |
| 7644 |
"updateImpl will not be called"); |
--- |
7644 |
"updateImpl will not be called"); |
--- |
| 7645 |
} |
--- |
7645 |
} |
--- |
| 7646 |
|
--- |
7646 |
|
--- |
| 7647 |
/// See AAPrivatizablePtrImpl::identifyPrivatizableType(...) |
--- |
7647 |
/// See AAPrivatizablePtrImpl::identifyPrivatizableType(...) |
--- |
| 7648 |
std::optional identifyPrivatizableType(Attributor &A) override { |
0 |
7648 |
std::optional identifyPrivatizableType(Attributor &A) override { |
0 |
| 7649 |
Value *Obj = getUnderlyingObject(&getAssociatedValue()); |
0 |
7649 |
Value *Obj = getUnderlyingObject(&getAssociatedValue()); |
0 |
| 7650 |
if (!Obj) { |
0 |
7650 |
if (!Obj) { |
0 |
| 7651 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] No underlying object found!\n"); |
0 |
7651 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] No underlying object found!\n"); |
0 |
| 7652 |
return nullptr; |
0 |
7652 |
return nullptr; |
0 |
| 7653 |
} |
--- |
7653 |
} |
--- |
| 7654 |
|
--- |
7654 |
|
--- |
| 7655 |
if (auto *AI = dyn_cast(Obj)) |
0 |
7655 |
if (auto *AI = dyn_cast(Obj)) |
0 |
| 7656 |
if (auto *CI = dyn_cast(AI->getArraySize())) |
0 |
7656 |
if (auto *CI = dyn_cast(AI->getArraySize())) |
0 |
| 7657 |
if (CI->isOne()) |
0 |
7657 |
if (CI->isOne()) |
0 |
| 7658 |
return AI->getAllocatedType(); |
0 |
7658 |
return AI->getAllocatedType(); |
0 |
| 7659 |
if (auto *Arg = dyn_cast(Obj)) { |
0 |
7659 |
if (auto *Arg = dyn_cast(Obj)) { |
0 |
| 7660 |
auto *PrivArgAA = A.getAAFor( |
0 |
7660 |
auto *PrivArgAA = A.getAAFor( |
0 |
| 7661 |
*this, IRPosition::argument(*Arg), DepClassTy::REQUIRED); |
0 |
7661 |
*this, IRPosition::argument(*Arg), DepClassTy::REQUIRED); |
0 |
| 7662 |
if (PrivArgAA && PrivArgAA->isAssumedPrivatizablePtr()) |
0 |
7662 |
if (PrivArgAA && PrivArgAA->isAssumedPrivatizablePtr()) |
0 |
| 7663 |
return PrivArgAA->getPrivatizableType(); |
0 |
7663 |
return PrivArgAA->getPrivatizableType(); |
0 |
| 7664 |
} |
--- |
7664 |
} |
--- |
| 7665 |
|
--- |
7665 |
|
--- |
| 7666 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] Underlying object neither valid " |
0 |
7666 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] Underlying object neither valid " |
0 |
| 7667 |
"alloca nor privatizable argument: " |
--- |
7667 |
"alloca nor privatizable argument: " |
--- |
| 7668 |
<< *Obj << "!\n"); |
--- |
7668 |
<< *Obj << "!\n"); |
--- |
| 7669 |
return nullptr; |
0 |
7669 |
return nullptr; |
0 |
| 7670 |
} |
--- |
7670 |
} |
--- |
| 7671 |
|
--- |
7671 |
|
--- |
| 7672 |
/// See AbstractAttribute::trackStatistics() |
--- |
7672 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 7673 |
void trackStatistics() const override { |
0 |
7673 |
void trackStatistics() const override { |
0 |
| 7674 |
STATS_DECLTRACK_FLOATING_ATTR(privatizable_ptr); |
0 |
7674 |
STATS_DECLTRACK_FLOATING_ATTR(privatizable_ptr); |
0 |
| 7675 |
} |
0 |
7675 |
} |
0 |
| 7676 |
}; |
--- |
7676 |
}; |
--- |
| 7677 |
|
--- |
7677 |
|
--- |
| 7678 |
struct AAPrivatizablePtrCallSiteArgument final |
--- |
7678 |
struct AAPrivatizablePtrCallSiteArgument final |
--- |
| 7679 |
: public AAPrivatizablePtrFloating { |
--- |
7679 |
: public AAPrivatizablePtrFloating { |
--- |
| 7680 |
AAPrivatizablePtrCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
7680 |
AAPrivatizablePtrCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 7681 |
: AAPrivatizablePtrFloating(IRP, A) {} |
0 |
7681 |
: AAPrivatizablePtrFloating(IRP, A) {} |
0 |
| 7682 |
|
--- |
7682 |
|
--- |
| 7683 |
/// See AbstractAttribute::initialize(...). |
--- |
7683 |
/// See AbstractAttribute::initialize(...). |
--- |
| 7684 |
void initialize(Attributor &A) override { |
0 |
7684 |
void initialize(Attributor &A) override { |
0 |
| 7685 |
if (A.hasAttr(getIRPosition(), Attribute::ByVal)) |
0 |
7685 |
if (A.hasAttr(getIRPosition(), Attribute::ByVal)) |
0 |
| 7686 |
indicateOptimisticFixpoint(); |
0 |
7686 |
indicateOptimisticFixpoint(); |
0 |
| 7687 |
} |
0 |
7687 |
} |
0 |
| 7688 |
|
--- |
7688 |
|
--- |
| 7689 |
/// See AbstractAttribute::updateImpl(...). |
--- |
7689 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 7690 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
7690 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 7691 |
PrivatizableType = identifyPrivatizableType(A); |
0 |
7691 |
PrivatizableType = identifyPrivatizableType(A); |
0 |
| 7692 |
if (!PrivatizableType) |
0 |
7692 |
if (!PrivatizableType) |
0 |
| 7693 |
return ChangeStatus::UNCHANGED; |
0 |
7693 |
return ChangeStatus::UNCHANGED; |
0 |
| 7694 |
if (!*PrivatizableType) |
0 |
7694 |
if (!*PrivatizableType) |
0 |
| 7695 |
return indicatePessimisticFixpoint(); |
0 |
7695 |
return indicatePessimisticFixpoint(); |
0 |
| 7696 |
|
--- |
7696 |
|
--- |
| 7697 |
const IRPosition &IRP = getIRPosition(); |
0 |
7697 |
const IRPosition &IRP = getIRPosition(); |
0 |
| 7698 |
bool IsKnownNoCapture; |
--- |
7698 |
bool IsKnownNoCapture; |
--- |
| 7699 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
7699 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
| 7700 |
A, this, IRP, DepClassTy::REQUIRED, IsKnownNoCapture); |
--- |
7700 |
A, this, IRP, DepClassTy::REQUIRED, IsKnownNoCapture); |
--- |
| 7701 |
if (!IsAssumedNoCapture) { |
0 |
7701 |
if (!IsAssumedNoCapture) { |
0 |
| 7702 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] pointer might be captured!\n"); |
0 |
7702 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] pointer might be captured!\n"); |
0 |
| 7703 |
return indicatePessimisticFixpoint(); |
0 |
7703 |
return indicatePessimisticFixpoint(); |
0 |
| 7704 |
} |
--- |
7704 |
} |
--- |
| 7705 |
|
--- |
7705 |
|
--- |
| 7706 |
bool IsKnownNoAlias; |
--- |
7706 |
bool IsKnownNoAlias; |
--- |
| 7707 |
if (!AA::hasAssumedIRAttr( |
0 |
7707 |
if (!AA::hasAssumedIRAttr( |
0 |
| 7708 |
A, this, IRP, DepClassTy::REQUIRED, IsKnownNoAlias)) { |
--- |
7708 |
A, this, IRP, DepClassTy::REQUIRED, IsKnownNoAlias)) { |
--- |
| 7709 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] pointer might alias!\n"); |
0 |
7709 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] pointer might alias!\n"); |
0 |
| 7710 |
return indicatePessimisticFixpoint(); |
0 |
7710 |
return indicatePessimisticFixpoint(); |
0 |
| 7711 |
} |
--- |
7711 |
} |
--- |
| 7712 |
|
--- |
7712 |
|
--- |
| 7713 |
bool IsKnown; |
--- |
7713 |
bool IsKnown; |
--- |
| 7714 |
if (!AA::isAssumedReadOnly(A, IRP, *this, IsKnown)) { |
0 |
7714 |
if (!AA::isAssumedReadOnly(A, IRP, *this, IsKnown)) { |
0 |
| 7715 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] pointer is written!\n"); |
0 |
7715 |
LLVM_DEBUG(dbgs() << "[AAPrivatizablePtr] pointer is written!\n"); |
0 |
| 7716 |
return indicatePessimisticFixpoint(); |
0 |
7716 |
return indicatePessimisticFixpoint(); |
0 |
| 7717 |
} |
--- |
7717 |
} |
--- |
| 7718 |
|
--- |
7718 |
|
--- |
| 7719 |
return ChangeStatus::UNCHANGED; |
0 |
7719 |
return ChangeStatus::UNCHANGED; |
0 |
| 7720 |
} |
--- |
7720 |
} |
--- |
| 7721 |
|
--- |
7721 |
|
--- |
| 7722 |
/// See AbstractAttribute::trackStatistics() |
--- |
7722 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 7723 |
void trackStatistics() const override { |
0 |
7723 |
void trackStatistics() const override { |
0 |
| 7724 |
STATS_DECLTRACK_CSARG_ATTR(privatizable_ptr); |
0 |
7724 |
STATS_DECLTRACK_CSARG_ATTR(privatizable_ptr); |
0 |
| 7725 |
} |
0 |
7725 |
} |
0 |
| 7726 |
}; |
--- |
7726 |
}; |
--- |
| 7727 |
|
--- |
7727 |
|
--- |
| 7728 |
struct AAPrivatizablePtrCallSiteReturned final |
--- |
7728 |
struct AAPrivatizablePtrCallSiteReturned final |
--- |
| 7729 |
: public AAPrivatizablePtrFloating { |
--- |
7729 |
: public AAPrivatizablePtrFloating { |
--- |
| 7730 |
AAPrivatizablePtrCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
7730 |
AAPrivatizablePtrCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 7731 |
: AAPrivatizablePtrFloating(IRP, A) {} |
0 |
7731 |
: AAPrivatizablePtrFloating(IRP, A) {} |
0 |
| 7732 |
|
--- |
7732 |
|
--- |
| 7733 |
/// See AbstractAttribute::initialize(...). |
--- |
7733 |
/// See AbstractAttribute::initialize(...). |
--- |
| 7734 |
void initialize(Attributor &A) override { |
0 |
7734 |
void initialize(Attributor &A) override { |
0 |
| 7735 |
// TODO: We can privatize more than arguments. |
--- |
7735 |
// TODO: We can privatize more than arguments. |
--- |
| 7736 |
indicatePessimisticFixpoint(); |
0 |
7736 |
indicatePessimisticFixpoint(); |
0 |
| 7737 |
} |
0 |
7737 |
} |
0 |
| 7738 |
|
--- |
7738 |
|
--- |
| 7739 |
/// See AbstractAttribute::trackStatistics() |
--- |
7739 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 7740 |
void trackStatistics() const override { |
0 |
7740 |
void trackStatistics() const override { |
0 |
| 7741 |
STATS_DECLTRACK_CSRET_ATTR(privatizable_ptr); |
0 |
7741 |
STATS_DECLTRACK_CSRET_ATTR(privatizable_ptr); |
0 |
| 7742 |
} |
0 |
7742 |
} |
0 |
| 7743 |
}; |
--- |
7743 |
}; |
--- |
| 7744 |
|
--- |
7744 |
|
--- |
| 7745 |
struct AAPrivatizablePtrReturned final : public AAPrivatizablePtrFloating { |
--- |
7745 |
struct AAPrivatizablePtrReturned final : public AAPrivatizablePtrFloating { |
--- |
| 7746 |
AAPrivatizablePtrReturned(const IRPosition &IRP, Attributor &A) |
0 |
7746 |
AAPrivatizablePtrReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 7747 |
: AAPrivatizablePtrFloating(IRP, A) {} |
0 |
7747 |
: AAPrivatizablePtrFloating(IRP, A) {} |
0 |
| 7748 |
|
--- |
7748 |
|
--- |
| 7749 |
/// See AbstractAttribute::initialize(...). |
--- |
7749 |
/// See AbstractAttribute::initialize(...). |
--- |
| 7750 |
void initialize(Attributor &A) override { |
0 |
7750 |
void initialize(Attributor &A) override { |
0 |
| 7751 |
// TODO: We can privatize more than arguments. |
--- |
7751 |
// TODO: We can privatize more than arguments. |
--- |
| 7752 |
indicatePessimisticFixpoint(); |
0 |
7752 |
indicatePessimisticFixpoint(); |
0 |
| 7753 |
} |
0 |
7753 |
} |
0 |
| 7754 |
|
--- |
7754 |
|
--- |
| 7755 |
/// See AbstractAttribute::trackStatistics() |
--- |
7755 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 7756 |
void trackStatistics() const override { |
0 |
7756 |
void trackStatistics() const override { |
0 |
| 7757 |
STATS_DECLTRACK_FNRET_ATTR(privatizable_ptr); |
0 |
7757 |
STATS_DECLTRACK_FNRET_ATTR(privatizable_ptr); |
0 |
| 7758 |
} |
0 |
7758 |
} |
0 |
| 7759 |
}; |
--- |
7759 |
}; |
--- |
| 7760 |
} // namespace |
--- |
7760 |
} // namespace |
--- |
| 7761 |
|
--- |
7761 |
|
--- |
| 7762 |
/// -------------------- Memory Behavior Attributes ---------------------------- |
--- |
7762 |
/// -------------------- Memory Behavior Attributes ---------------------------- |
--- |
| 7763 |
/// Includes read-none, read-only, and write-only. |
--- |
7763 |
/// Includes read-none, read-only, and write-only. |
--- |
| 7764 |
/// ---------------------------------------------------------------------------- |
--- |
7764 |
/// ---------------------------------------------------------------------------- |
--- |
| 7765 |
namespace { |
--- |
7765 |
namespace { |
--- |
| 7766 |
struct AAMemoryBehaviorImpl : public AAMemoryBehavior { |
--- |
7766 |
struct AAMemoryBehaviorImpl : public AAMemoryBehavior { |
--- |
| 7767 |
AAMemoryBehaviorImpl(const IRPosition &IRP, Attributor &A) |
0 |
7767 |
AAMemoryBehaviorImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 7768 |
: AAMemoryBehavior(IRP, A) {} |
0 |
7768 |
: AAMemoryBehavior(IRP, A) {} |
0 |
| 7769 |
|
--- |
7769 |
|
--- |
| 7770 |
/// See AbstractAttribute::initialize(...). |
--- |
7770 |
/// See AbstractAttribute::initialize(...). |
--- |
| 7771 |
void initialize(Attributor &A) override { |
0 |
7771 |
void initialize(Attributor &A) override { |
0 |
| 7772 |
intersectAssumedBits(BEST_STATE); |
0 |
7772 |
intersectAssumedBits(BEST_STATE); |
0 |
| 7773 |
getKnownStateFromValue(A, getIRPosition(), getState()); |
0 |
7773 |
getKnownStateFromValue(A, getIRPosition(), getState()); |
0 |
| 7774 |
AAMemoryBehavior::initialize(A); |
0 |
7774 |
AAMemoryBehavior::initialize(A); |
0 |
| 7775 |
} |
0 |
7775 |
} |
0 |
| 7776 |
|
--- |
7776 |
|
--- |
| 7777 |
/// Return the memory behavior information encoded in the IR for \p IRP. |
--- |
7777 |
/// Return the memory behavior information encoded in the IR for \p IRP. |
--- |
| 7778 |
static void getKnownStateFromValue(Attributor &A, const IRPosition &IRP, |
0 |
7778 |
static void getKnownStateFromValue(Attributor &A, const IRPosition &IRP, |
0 |
| 7779 |
BitIntegerState &State, |
--- |
7779 |
BitIntegerState &State, |
--- |
| 7780 |
bool IgnoreSubsumingPositions = false) { |
--- |
7780 |
bool IgnoreSubsumingPositions = false) { |
--- |
| 7781 |
SmallVector Attrs; |
0 |
7781 |
SmallVector Attrs; |
0 |
| 7782 |
A.getAttrs(IRP, AttrKinds, Attrs, IgnoreSubsumingPositions); |
0 |
7782 |
A.getAttrs(IRP, AttrKinds, Attrs, IgnoreSubsumingPositions); |
0 |
| 7783 |
for (const Attribute &Attr : Attrs) { |
0 |
7783 |
for (const Attribute &Attr : Attrs) { |
0 |
| 7784 |
switch (Attr.getKindAsEnum()) { |
0 |
7784 |
switch (Attr.getKindAsEnum()) { |
0 |
| 7785 |
case Attribute::ReadNone: |
0 |
7785 |
case Attribute::ReadNone: |
0 |
| 7786 |
State.addKnownBits(NO_ACCESSES); |
0 |
7786 |
State.addKnownBits(NO_ACCESSES); |
0 |
| 7787 |
break; |
0 |
7787 |
break; |
0 |
| 7788 |
case Attribute::ReadOnly: |
0 |
7788 |
case Attribute::ReadOnly: |
0 |
| 7789 |
State.addKnownBits(NO_WRITES); |
0 |
7789 |
State.addKnownBits(NO_WRITES); |
0 |
| 7790 |
break; |
0 |
7790 |
break; |
0 |
| 7791 |
case Attribute::WriteOnly: |
0 |
7791 |
case Attribute::WriteOnly: |
0 |
| 7792 |
State.addKnownBits(NO_READS); |
0 |
7792 |
State.addKnownBits(NO_READS); |
0 |
| 7793 |
break; |
0 |
7793 |
break; |
0 |
| 7794 |
default: |
0 |
7794 |
default: |
0 |
| 7795 |
llvm_unreachable("Unexpected attribute!"); |
0 |
7795 |
llvm_unreachable("Unexpected attribute!"); |
0 |
| 7796 |
} |
--- |
7796 |
} |
--- |
| 7797 |
} |
--- |
7797 |
} |
--- |
| 7798 |
|
--- |
7798 |
|
--- |
| 7799 |
if (auto *I = dyn_cast(&IRP.getAnchorValue())) { |
0 |
7799 |
if (auto *I = dyn_cast(&IRP.getAnchorValue())) { |
0 |
| 7800 |
if (!I->mayReadFromMemory()) |
0 |
7800 |
if (!I->mayReadFromMemory()) |
0 |
| 7801 |
State.addKnownBits(NO_READS); |
0 |
7801 |
State.addKnownBits(NO_READS); |
0 |
| 7802 |
if (!I->mayWriteToMemory()) |
0 |
7802 |
if (!I->mayWriteToMemory()) |
0 |
| 7803 |
State.addKnownBits(NO_WRITES); |
0 |
7803 |
State.addKnownBits(NO_WRITES); |
0 |
| 7804 |
} |
--- |
7804 |
} |
--- |
| 7805 |
} |
0 |
7805 |
} |
0 |
| 7806 |
|
--- |
7806 |
|
--- |
| 7807 |
/// See AbstractAttribute::getDeducedAttributes(...). |
--- |
7807 |
/// See AbstractAttribute::getDeducedAttributes(...). |
--- |
| 7808 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
7808 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
| 7809 |
SmallVectorImpl &Attrs) const override { |
--- |
7809 |
SmallVectorImpl &Attrs) const override { |
--- |
| 7810 |
assert(Attrs.size() == 0); |
0 |
7810 |
assert(Attrs.size() == 0); |
0 |
| 7811 |
if (isAssumedReadNone()) |
0 |
7811 |
if (isAssumedReadNone()) |
0 |
| 7812 |
Attrs.push_back(Attribute::get(Ctx, Attribute::ReadNone)); |
0 |
7812 |
Attrs.push_back(Attribute::get(Ctx, Attribute::ReadNone)); |
0 |
| 7813 |
else if (isAssumedReadOnly()) |
0 |
7813 |
else if (isAssumedReadOnly()) |
0 |
| 7814 |
Attrs.push_back(Attribute::get(Ctx, Attribute::ReadOnly)); |
0 |
7814 |
Attrs.push_back(Attribute::get(Ctx, Attribute::ReadOnly)); |
0 |
| 7815 |
else if (isAssumedWriteOnly()) |
0 |
7815 |
else if (isAssumedWriteOnly()) |
0 |
| 7816 |
Attrs.push_back(Attribute::get(Ctx, Attribute::WriteOnly)); |
0 |
7816 |
Attrs.push_back(Attribute::get(Ctx, Attribute::WriteOnly)); |
0 |
| 7817 |
assert(Attrs.size() <= 1); |
0 |
7817 |
assert(Attrs.size() <= 1); |
0 |
| 7818 |
} |
0 |
7818 |
} |
0 |
| 7819 |
|
--- |
7819 |
|
--- |
| 7820 |
/// See AbstractAttribute::manifest(...). |
--- |
7820 |
/// See AbstractAttribute::manifest(...). |
--- |
| 7821 |
ChangeStatus manifest(Attributor &A) override { |
0 |
7821 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 7822 |
const IRPosition &IRP = getIRPosition(); |
0 |
7822 |
const IRPosition &IRP = getIRPosition(); |
0 |
| 7823 |
|
--- |
7823 |
|
--- |
| 7824 |
if (A.hasAttr(IRP, Attribute::ReadNone, |
0 |
7824 |
if (A.hasAttr(IRP, Attribute::ReadNone, |
0 |
| 7825 |
/* IgnoreSubsumingPositions */ true)) |
--- |
7825 |
/* IgnoreSubsumingPositions */ true)) |
--- |
| 7826 |
return ChangeStatus::UNCHANGED; |
0 |
7826 |
return ChangeStatus::UNCHANGED; |
0 |
| 7827 |
|
--- |
7827 |
|
--- |
| 7828 |
// Check if we would improve the existing attributes first. |
--- |
7828 |
// Check if we would improve the existing attributes first. |
--- |
| 7829 |
SmallVector DeducedAttrs; |
0 |
7829 |
SmallVector DeducedAttrs; |
0 |
| 7830 |
getDeducedAttributes(A, IRP.getAnchorValue().getContext(), DeducedAttrs); |
0 |
7830 |
getDeducedAttributes(A, IRP.getAnchorValue().getContext(), DeducedAttrs); |
0 |
| 7831 |
if (llvm::all_of(DeducedAttrs, [&](const Attribute &Attr) { |
0 |
7831 |
if (llvm::all_of(DeducedAttrs, [&](const Attribute &Attr) { |
0 |
| 7832 |
return A.hasAttr(IRP, Attr.getKindAsEnum(), |
0 |
7832 |
return A.hasAttr(IRP, Attr.getKindAsEnum(), |
0 |
| 7833 |
/* IgnoreSubsumingPositions */ true); |
0 |
7833 |
/* IgnoreSubsumingPositions */ true); |
0 |
| 7834 |
})) |
--- |
7834 |
})) |
--- |
| 7835 |
return ChangeStatus::UNCHANGED; |
0 |
7835 |
return ChangeStatus::UNCHANGED; |
0 |
| 7836 |
|
--- |
7836 |
|
--- |
| 7837 |
// Clear existing attributes. |
--- |
7837 |
// Clear existing attributes. |
--- |
| 7838 |
A.removeAttrs(IRP, AttrKinds); |
0 |
7838 |
A.removeAttrs(IRP, AttrKinds); |
0 |
| 7839 |
|
--- |
7839 |
|
--- |
| 7840 |
// Use the generic manifest method. |
--- |
7840 |
// Use the generic manifest method. |
--- |
| 7841 |
return IRAttribute::manifest(A); |
0 |
7841 |
return IRAttribute::manifest(A); |
0 |
| 7842 |
} |
0 |
7842 |
} |
0 |
| 7843 |
|
--- |
7843 |
|
--- |
| 7844 |
/// See AbstractState::getAsStr(). |
--- |
7844 |
/// See AbstractState::getAsStr(). |
--- |
| 7845 |
const std::string getAsStr(Attributor *A) const override { |
0 |
7845 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 7846 |
if (isAssumedReadNone()) |
0 |
7846 |
if (isAssumedReadNone()) |
0 |
| 7847 |
return "readnone"; |
0 |
7847 |
return "readnone"; |
0 |
| 7848 |
if (isAssumedReadOnly()) |
0 |
7848 |
if (isAssumedReadOnly()) |
0 |
| 7849 |
return "readonly"; |
0 |
7849 |
return "readonly"; |
0 |
| 7850 |
if (isAssumedWriteOnly()) |
0 |
7850 |
if (isAssumedWriteOnly()) |
0 |
| 7851 |
return "writeonly"; |
0 |
7851 |
return "writeonly"; |
0 |
| 7852 |
return "may-read/write"; |
0 |
7852 |
return "may-read/write"; |
0 |
| 7853 |
} |
--- |
7853 |
} |
--- |
| 7854 |
|
--- |
7854 |
|
--- |
| 7855 |
/// The set of IR attributes AAMemoryBehavior deals with. |
--- |
7855 |
/// The set of IR attributes AAMemoryBehavior deals with. |
--- |
| 7856 |
static const Attribute::AttrKind AttrKinds[3]; |
--- |
7856 |
static const Attribute::AttrKind AttrKinds[3]; |
--- |
| 7857 |
}; |
--- |
7857 |
}; |
--- |
| 7858 |
|
--- |
7858 |
|
--- |
| 7859 |
const Attribute::AttrKind AAMemoryBehaviorImpl::AttrKinds[] = { |
--- |
7859 |
const Attribute::AttrKind AAMemoryBehaviorImpl::AttrKinds[] = { |
--- |
| 7860 |
Attribute::ReadNone, Attribute::ReadOnly, Attribute::WriteOnly}; |
--- |
7860 |
Attribute::ReadNone, Attribute::ReadOnly, Attribute::WriteOnly}; |
--- |
| 7861 |
|
--- |
7861 |
|
--- |
| 7862 |
/// Memory behavior attribute for a floating value. |
--- |
7862 |
/// Memory behavior attribute for a floating value. |
--- |
| 7863 |
struct AAMemoryBehaviorFloating : AAMemoryBehaviorImpl { |
--- |
7863 |
struct AAMemoryBehaviorFloating : AAMemoryBehaviorImpl { |
--- |
| 7864 |
AAMemoryBehaviorFloating(const IRPosition &IRP, Attributor &A) |
0 |
7864 |
AAMemoryBehaviorFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 7865 |
: AAMemoryBehaviorImpl(IRP, A) {} |
0 |
7865 |
: AAMemoryBehaviorImpl(IRP, A) {} |
0 |
| 7866 |
|
--- |
7866 |
|
--- |
| 7867 |
/// See AbstractAttribute::updateImpl(...). |
--- |
7867 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 7868 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
7868 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
| 7869 |
|
--- |
7869 |
|
--- |
| 7870 |
/// See AbstractAttribute::trackStatistics() |
--- |
7870 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 7871 |
void trackStatistics() const override { |
0 |
7871 |
void trackStatistics() const override { |
0 |
| 7872 |
if (isAssumedReadNone()) |
0 |
7872 |
if (isAssumedReadNone()) |
0 |
| 7873 |
STATS_DECLTRACK_FLOATING_ATTR(readnone) |
0 |
7873 |
STATS_DECLTRACK_FLOATING_ATTR(readnone) |
0 |
| 7874 |
else if (isAssumedReadOnly()) |
0 |
7874 |
else if (isAssumedReadOnly()) |
0 |
| 7875 |
STATS_DECLTRACK_FLOATING_ATTR(readonly) |
0 |
7875 |
STATS_DECLTRACK_FLOATING_ATTR(readonly) |
0 |
| 7876 |
else if (isAssumedWriteOnly()) |
0 |
7876 |
else if (isAssumedWriteOnly()) |
0 |
| 7877 |
STATS_DECLTRACK_FLOATING_ATTR(writeonly) |
0 |
7877 |
STATS_DECLTRACK_FLOATING_ATTR(writeonly) |
0 |
| 7878 |
} |
0 |
7878 |
} |
0 |
| 7879 |
|
--- |
7879 |
|
--- |
| 7880 |
private: |
--- |
7880 |
private: |
--- |
| 7881 |
/// Return true if users of \p UserI might access the underlying |
--- |
7881 |
/// Return true if users of \p UserI might access the underlying |
--- |
| 7882 |
/// variable/location described by \p U and should therefore be analyzed. |
--- |
7882 |
/// variable/location described by \p U and should therefore be analyzed. |
--- |
| 7883 |
bool followUsersOfUseIn(Attributor &A, const Use &U, |
--- |
7883 |
bool followUsersOfUseIn(Attributor &A, const Use &U, |
--- |
| 7884 |
const Instruction *UserI); |
--- |
7884 |
const Instruction *UserI); |
--- |
| 7885 |
|
--- |
7885 |
|
--- |
| 7886 |
/// Update the state according to the effect of use \p U in \p UserI. |
--- |
7886 |
/// Update the state according to the effect of use \p U in \p UserI. |
--- |
| 7887 |
void analyzeUseIn(Attributor &A, const Use &U, const Instruction *UserI); |
--- |
7887 |
void analyzeUseIn(Attributor &A, const Use &U, const Instruction *UserI); |
--- |
| 7888 |
}; |
--- |
7888 |
}; |
--- |
| 7889 |
|
--- |
7889 |
|
--- |
| 7890 |
/// Memory behavior attribute for function argument. |
--- |
7890 |
/// Memory behavior attribute for function argument. |
--- |
| 7891 |
struct AAMemoryBehaviorArgument : AAMemoryBehaviorFloating { |
--- |
7891 |
struct AAMemoryBehaviorArgument : AAMemoryBehaviorFloating { |
--- |
| 7892 |
AAMemoryBehaviorArgument(const IRPosition &IRP, Attributor &A) |
0 |
7892 |
AAMemoryBehaviorArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 7893 |
: AAMemoryBehaviorFloating(IRP, A) {} |
0 |
7893 |
: AAMemoryBehaviorFloating(IRP, A) {} |
0 |
| 7894 |
|
--- |
7894 |
|
--- |
| 7895 |
/// See AbstractAttribute::initialize(...). |
--- |
7895 |
/// See AbstractAttribute::initialize(...). |
--- |
| 7896 |
void initialize(Attributor &A) override { |
0 |
7896 |
void initialize(Attributor &A) override { |
0 |
| 7897 |
intersectAssumedBits(BEST_STATE); |
0 |
7897 |
intersectAssumedBits(BEST_STATE); |
0 |
| 7898 |
const IRPosition &IRP = getIRPosition(); |
0 |
7898 |
const IRPosition &IRP = getIRPosition(); |
0 |
| 7899 |
// TODO: Make IgnoreSubsumingPositions a property of an IRAttribute so we |
--- |
7899 |
// TODO: Make IgnoreSubsumingPositions a property of an IRAttribute so we |
--- |
| 7900 |
// can query it when we use has/getAttr. That would allow us to reuse the |
--- |
7900 |
// can query it when we use has/getAttr. That would allow us to reuse the |
--- |
| 7901 |
// initialize of the base class here. |
--- |
7901 |
// initialize of the base class here. |
--- |
| 7902 |
bool HasByVal = A.hasAttr(IRP, {Attribute::ByVal}, |
0 |
7902 |
bool HasByVal = A.hasAttr(IRP, {Attribute::ByVal}, |
0 |
| 7903 |
/* IgnoreSubsumingPositions */ true); |
--- |
7903 |
/* IgnoreSubsumingPositions */ true); |
--- |
| 7904 |
getKnownStateFromValue(A, IRP, getState(), |
0 |
7904 |
getKnownStateFromValue(A, IRP, getState(), |
0 |
| 7905 |
/* IgnoreSubsumingPositions */ HasByVal); |
--- |
7905 |
/* IgnoreSubsumingPositions */ HasByVal); |
--- |
| 7906 |
} |
0 |
7906 |
} |
0 |
| 7907 |
|
--- |
7907 |
|
--- |
| 7908 |
ChangeStatus manifest(Attributor &A) override { |
0 |
7908 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 7909 |
// TODO: Pointer arguments are not supported on vectors of pointers yet. |
--- |
7909 |
// TODO: Pointer arguments are not supported on vectors of pointers yet. |
--- |
| 7910 |
if (!getAssociatedValue().getType()->isPointerTy()) |
0 |
7910 |
if (!getAssociatedValue().getType()->isPointerTy()) |
0 |
| 7911 |
return ChangeStatus::UNCHANGED; |
0 |
7911 |
return ChangeStatus::UNCHANGED; |
0 |
| 7912 |
|
--- |
7912 |
|
--- |
| 7913 |
// TODO: From readattrs.ll: "inalloca parameters are always |
--- |
7913 |
// TODO: From readattrs.ll: "inalloca parameters are always |
--- |
| 7914 |
// considered written" |
--- |
7914 |
// considered written" |
--- |
| 7915 |
if (A.hasAttr(getIRPosition(), |
0 |
7915 |
if (A.hasAttr(getIRPosition(), |
0 |
| 7916 |
{Attribute::InAlloca, Attribute::Preallocated})) { |
--- |
7916 |
{Attribute::InAlloca, Attribute::Preallocated})) { |
--- |
| 7917 |
removeKnownBits(NO_WRITES); |
0 |
7917 |
removeKnownBits(NO_WRITES); |
0 |
| 7918 |
removeAssumedBits(NO_WRITES); |
0 |
7918 |
removeAssumedBits(NO_WRITES); |
0 |
| 7919 |
} |
--- |
7919 |
} |
--- |
| 7920 |
A.removeAttrs(getIRPosition(), AttrKinds); |
0 |
7920 |
A.removeAttrs(getIRPosition(), AttrKinds); |
0 |
| 7921 |
return AAMemoryBehaviorFloating::manifest(A); |
0 |
7921 |
return AAMemoryBehaviorFloating::manifest(A); |
0 |
| 7922 |
} |
--- |
7922 |
} |
--- |
| 7923 |
|
--- |
7923 |
|
--- |
| 7924 |
/// See AbstractAttribute::trackStatistics() |
--- |
7924 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 7925 |
void trackStatistics() const override { |
0 |
7925 |
void trackStatistics() const override { |
0 |
| 7926 |
if (isAssumedReadNone()) |
0 |
7926 |
if (isAssumedReadNone()) |
0 |
| 7927 |
STATS_DECLTRACK_ARG_ATTR(readnone) |
0 |
7927 |
STATS_DECLTRACK_ARG_ATTR(readnone) |
0 |
| 7928 |
else if (isAssumedReadOnly()) |
0 |
7928 |
else if (isAssumedReadOnly()) |
0 |
| 7929 |
STATS_DECLTRACK_ARG_ATTR(readonly) |
0 |
7929 |
STATS_DECLTRACK_ARG_ATTR(readonly) |
0 |
| 7930 |
else if (isAssumedWriteOnly()) |
0 |
7930 |
else if (isAssumedWriteOnly()) |
0 |
| 7931 |
STATS_DECLTRACK_ARG_ATTR(writeonly) |
0 |
7931 |
STATS_DECLTRACK_ARG_ATTR(writeonly) |
0 |
| 7932 |
} |
0 |
7932 |
} |
0 |
| 7933 |
}; |
--- |
7933 |
}; |
--- |
| 7934 |
|
--- |
7934 |
|
--- |
| 7935 |
struct AAMemoryBehaviorCallSiteArgument final : AAMemoryBehaviorArgument { |
--- |
7935 |
struct AAMemoryBehaviorCallSiteArgument final : AAMemoryBehaviorArgument { |
--- |
| 7936 |
AAMemoryBehaviorCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
7936 |
AAMemoryBehaviorCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 7937 |
: AAMemoryBehaviorArgument(IRP, A) {} |
0 |
7937 |
: AAMemoryBehaviorArgument(IRP, A) {} |
0 |
| 7938 |
|
--- |
7938 |
|
--- |
| 7939 |
/// See AbstractAttribute::initialize(...). |
--- |
7939 |
/// See AbstractAttribute::initialize(...). |
--- |
| 7940 |
void initialize(Attributor &A) override { |
0 |
7940 |
void initialize(Attributor &A) override { |
0 |
| 7941 |
// If we don't have an associated attribute this is either a variadic call |
--- |
7941 |
// If we don't have an associated attribute this is either a variadic call |
--- |
| 7942 |
// or an indirect call, either way, nothing to do here. |
--- |
7942 |
// or an indirect call, either way, nothing to do here. |
--- |
| 7943 |
Argument *Arg = getAssociatedArgument(); |
0 |
7943 |
Argument *Arg = getAssociatedArgument(); |
0 |
| 7944 |
if (!Arg) { |
0 |
7944 |
if (!Arg) { |
0 |
| 7945 |
indicatePessimisticFixpoint(); |
0 |
7945 |
indicatePessimisticFixpoint(); |
0 |
| 7946 |
return; |
0 |
7946 |
return; |
0 |
| 7947 |
} |
--- |
7947 |
} |
--- |
| 7948 |
if (Arg->hasByValAttr()) { |
0 |
7948 |
if (Arg->hasByValAttr()) { |
0 |
| 7949 |
addKnownBits(NO_WRITES); |
0 |
7949 |
addKnownBits(NO_WRITES); |
0 |
| 7950 |
removeKnownBits(NO_READS); |
0 |
7950 |
removeKnownBits(NO_READS); |
0 |
| 7951 |
removeAssumedBits(NO_READS); |
0 |
7951 |
removeAssumedBits(NO_READS); |
0 |
| 7952 |
} |
--- |
7952 |
} |
--- |
| 7953 |
AAMemoryBehaviorArgument::initialize(A); |
0 |
7953 |
AAMemoryBehaviorArgument::initialize(A); |
0 |
| 7954 |
if (getAssociatedFunction()->isDeclaration()) |
0 |
7954 |
if (getAssociatedFunction()->isDeclaration()) |
0 |
| 7955 |
indicatePessimisticFixpoint(); |
0 |
7955 |
indicatePessimisticFixpoint(); |
0 |
| 7956 |
} |
--- |
7956 |
} |
--- |
| 7957 |
|
--- |
7957 |
|
--- |
| 7958 |
/// See AbstractAttribute::updateImpl(...). |
--- |
7958 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 7959 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
7959 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 7960 |
// TODO: Once we have call site specific value information we can provide |
--- |
7960 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 7961 |
// call site specific liveness liveness information and then it makes |
--- |
7961 |
// call site specific liveness liveness information and then it makes |
--- |
| 7962 |
// sense to specialize attributes for call sites arguments instead of |
--- |
7962 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 7963 |
// redirecting requests to the callee argument. |
--- |
7963 |
// redirecting requests to the callee argument. |
--- |
| 7964 |
Argument *Arg = getAssociatedArgument(); |
0 |
7964 |
Argument *Arg = getAssociatedArgument(); |
0 |
| 7965 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
7965 |
const IRPosition &ArgPos = IRPosition::argument(*Arg); |
0 |
| 7966 |
auto *ArgAA = |
--- |
7966 |
auto *ArgAA = |
--- |
| 7967 |
A.getAAFor(*this, ArgPos, DepClassTy::REQUIRED); |
0 |
7967 |
A.getAAFor(*this, ArgPos, DepClassTy::REQUIRED); |
0 |
| 7968 |
if (!ArgAA) |
0 |
7968 |
if (!ArgAA) |
0 |
| 7969 |
return indicatePessimisticFixpoint(); |
0 |
7969 |
return indicatePessimisticFixpoint(); |
0 |
| 7970 |
return clampStateAndIndicateChange(getState(), ArgAA->getState()); |
0 |
7970 |
return clampStateAndIndicateChange(getState(), ArgAA->getState()); |
0 |
| 7971 |
} |
--- |
7971 |
} |
--- |
| 7972 |
|
--- |
7972 |
|
--- |
| 7973 |
/// See AbstractAttribute::trackStatistics() |
--- |
7973 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 7974 |
void trackStatistics() const override { |
0 |
7974 |
void trackStatistics() const override { |
0 |
| 7975 |
if (isAssumedReadNone()) |
0 |
7975 |
if (isAssumedReadNone()) |
0 |
| 7976 |
STATS_DECLTRACK_CSARG_ATTR(readnone) |
0 |
7976 |
STATS_DECLTRACK_CSARG_ATTR(readnone) |
0 |
| 7977 |
else if (isAssumedReadOnly()) |
0 |
7977 |
else if (isAssumedReadOnly()) |
0 |
| 7978 |
STATS_DECLTRACK_CSARG_ATTR(readonly) |
0 |
7978 |
STATS_DECLTRACK_CSARG_ATTR(readonly) |
0 |
| 7979 |
else if (isAssumedWriteOnly()) |
0 |
7979 |
else if (isAssumedWriteOnly()) |
0 |
| 7980 |
STATS_DECLTRACK_CSARG_ATTR(writeonly) |
0 |
7980 |
STATS_DECLTRACK_CSARG_ATTR(writeonly) |
0 |
| 7981 |
} |
0 |
7981 |
} |
0 |
| 7982 |
}; |
--- |
7982 |
}; |
--- |
| 7983 |
|
--- |
7983 |
|
--- |
| 7984 |
/// Memory behavior attribute for a call site return position. |
--- |
7984 |
/// Memory behavior attribute for a call site return position. |
--- |
| 7985 |
struct AAMemoryBehaviorCallSiteReturned final : AAMemoryBehaviorFloating { |
--- |
7985 |
struct AAMemoryBehaviorCallSiteReturned final : AAMemoryBehaviorFloating { |
--- |
| 7986 |
AAMemoryBehaviorCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
7986 |
AAMemoryBehaviorCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 7987 |
: AAMemoryBehaviorFloating(IRP, A) {} |
0 |
7987 |
: AAMemoryBehaviorFloating(IRP, A) {} |
0 |
| 7988 |
|
--- |
7988 |
|
--- |
| 7989 |
/// See AbstractAttribute::initialize(...). |
--- |
7989 |
/// See AbstractAttribute::initialize(...). |
--- |
| 7990 |
void initialize(Attributor &A) override { |
0 |
7990 |
void initialize(Attributor &A) override { |
0 |
| 7991 |
AAMemoryBehaviorImpl::initialize(A); |
0 |
7991 |
AAMemoryBehaviorImpl::initialize(A); |
0 |
| 7992 |
} |
0 |
7992 |
} |
0 |
| 7993 |
/// See AbstractAttribute::manifest(...). |
--- |
7993 |
/// See AbstractAttribute::manifest(...). |
--- |
| 7994 |
ChangeStatus manifest(Attributor &A) override { |
0 |
7994 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 7995 |
// We do not annotate returned values. |
--- |
7995 |
// We do not annotate returned values. |
--- |
| 7996 |
return ChangeStatus::UNCHANGED; |
0 |
7996 |
return ChangeStatus::UNCHANGED; |
0 |
| 7997 |
} |
--- |
7997 |
} |
--- |
| 7998 |
|
--- |
7998 |
|
--- |
| 7999 |
/// See AbstractAttribute::trackStatistics() |
--- |
7999 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 8000 |
void trackStatistics() const override {} |
0 |
8000 |
void trackStatistics() const override {} |
0 |
| 8001 |
}; |
--- |
8001 |
}; |
--- |
| 8002 |
|
--- |
8002 |
|
--- |
| 8003 |
/// An AA to represent the memory behavior function attributes. |
--- |
8003 |
/// An AA to represent the memory behavior function attributes. |
--- |
| 8004 |
struct AAMemoryBehaviorFunction final : public AAMemoryBehaviorImpl { |
--- |
8004 |
struct AAMemoryBehaviorFunction final : public AAMemoryBehaviorImpl { |
--- |
| 8005 |
AAMemoryBehaviorFunction(const IRPosition &IRP, Attributor &A) |
0 |
8005 |
AAMemoryBehaviorFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 8006 |
: AAMemoryBehaviorImpl(IRP, A) {} |
0 |
8006 |
: AAMemoryBehaviorImpl(IRP, A) {} |
0 |
| 8007 |
|
--- |
8007 |
|
--- |
| 8008 |
/// See AbstractAttribute::updateImpl(Attributor &A). |
--- |
8008 |
/// See AbstractAttribute::updateImpl(Attributor &A). |
--- |
| 8009 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
8009 |
ChangeStatus updateImpl(Attributor &A) override; |
--- |
| 8010 |
|
--- |
8010 |
|
--- |
| 8011 |
/// See AbstractAttribute::manifest(...). |
--- |
8011 |
/// See AbstractAttribute::manifest(...). |
--- |
| 8012 |
ChangeStatus manifest(Attributor &A) override { |
0 |
8012 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 8013 |
// TODO: It would be better to merge this with AAMemoryLocation, so that |
--- |
8013 |
// TODO: It would be better to merge this with AAMemoryLocation, so that |
--- |
| 8014 |
// we could determine read/write per location. This would also have the |
--- |
8014 |
// we could determine read/write per location. This would also have the |
--- |
| 8015 |
// benefit of only one place trying to manifest the memory attribute. |
--- |
8015 |
// benefit of only one place trying to manifest the memory attribute. |
--- |
| 8016 |
Function &F = cast(getAnchorValue()); |
0 |
8016 |
Function &F = cast(getAnchorValue()); |
0 |
| 8017 |
MemoryEffects ME = MemoryEffects::unknown(); |
0 |
8017 |
MemoryEffects ME = MemoryEffects::unknown(); |
0 |
| 8018 |
if (isAssumedReadNone()) |
0 |
8018 |
if (isAssumedReadNone()) |
0 |
| 8019 |
ME = MemoryEffects::none(); |
0 |
8019 |
ME = MemoryEffects::none(); |
0 |
| 8020 |
else if (isAssumedReadOnly()) |
0 |
8020 |
else if (isAssumedReadOnly()) |
0 |
| 8021 |
ME = MemoryEffects::readOnly(); |
0 |
8021 |
ME = MemoryEffects::readOnly(); |
0 |
| 8022 |
else if (isAssumedWriteOnly()) |
0 |
8022 |
else if (isAssumedWriteOnly()) |
0 |
| 8023 |
ME = MemoryEffects::writeOnly(); |
0 |
8023 |
ME = MemoryEffects::writeOnly(); |
0 |
| 8024 |
|
--- |
8024 |
|
--- |
| 8025 |
A.removeAttrs(getIRPosition(), AttrKinds); |
0 |
8025 |
A.removeAttrs(getIRPosition(), AttrKinds); |
0 |
| 8026 |
return A.manifestAttrs(getIRPosition(), |
0 |
8026 |
return A.manifestAttrs(getIRPosition(), |
0 |
| 8027 |
Attribute::getWithMemoryEffects(F.getContext(), ME)); |
0 |
8027 |
Attribute::getWithMemoryEffects(F.getContext(), ME)); |
0 |
| 8028 |
} |
--- |
8028 |
} |
--- |
| 8029 |
|
--- |
8029 |
|
--- |
| 8030 |
/// See AbstractAttribute::trackStatistics() |
--- |
8030 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 8031 |
void trackStatistics() const override { |
0 |
8031 |
void trackStatistics() const override { |
0 |
| 8032 |
if (isAssumedReadNone()) |
0 |
8032 |
if (isAssumedReadNone()) |
0 |
| 8033 |
STATS_DECLTRACK_FN_ATTR(readnone) |
0 |
8033 |
STATS_DECLTRACK_FN_ATTR(readnone) |
0 |
| 8034 |
else if (isAssumedReadOnly()) |
0 |
8034 |
else if (isAssumedReadOnly()) |
0 |
| 8035 |
STATS_DECLTRACK_FN_ATTR(readonly) |
0 |
8035 |
STATS_DECLTRACK_FN_ATTR(readonly) |
0 |
| 8036 |
else if (isAssumedWriteOnly()) |
0 |
8036 |
else if (isAssumedWriteOnly()) |
0 |
| 8037 |
STATS_DECLTRACK_FN_ATTR(writeonly) |
0 |
8037 |
STATS_DECLTRACK_FN_ATTR(writeonly) |
0 |
| 8038 |
} |
0 |
8038 |
} |
0 |
| 8039 |
}; |
--- |
8039 |
}; |
--- |
| 8040 |
|
--- |
8040 |
|
--- |
| 8041 |
/// AAMemoryBehavior attribute for call sites. |
--- |
8041 |
/// AAMemoryBehavior attribute for call sites. |
--- |
| 8042 |
struct AAMemoryBehaviorCallSite final : AAMemoryBehaviorImpl { |
--- |
8042 |
struct AAMemoryBehaviorCallSite final : AAMemoryBehaviorImpl { |
--- |
| 8043 |
AAMemoryBehaviorCallSite(const IRPosition &IRP, Attributor &A) |
0 |
8043 |
AAMemoryBehaviorCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 8044 |
: AAMemoryBehaviorImpl(IRP, A) {} |
0 |
8044 |
: AAMemoryBehaviorImpl(IRP, A) {} |
0 |
| 8045 |
|
--- |
8045 |
|
--- |
| 8046 |
/// See AbstractAttribute::updateImpl(...). |
--- |
8046 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 8047 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
8047 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 8048 |
// TODO: Once we have call site specific value information we can provide |
--- |
8048 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 8049 |
// call site specific liveness liveness information and then it makes |
--- |
8049 |
// call site specific liveness liveness information and then it makes |
--- |
| 8050 |
// sense to specialize attributes for call sites arguments instead of |
--- |
8050 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 8051 |
// redirecting requests to the callee argument. |
--- |
8051 |
// redirecting requests to the callee argument. |
--- |
| 8052 |
Function *F = getAssociatedFunction(); |
0 |
8052 |
Function *F = getAssociatedFunction(); |
0 |
| 8053 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
8053 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
| 8054 |
auto *FnAA = |
--- |
8054 |
auto *FnAA = |
--- |
| 8055 |
A.getAAFor(*this, FnPos, DepClassTy::REQUIRED); |
0 |
8055 |
A.getAAFor(*this, FnPos, DepClassTy::REQUIRED); |
0 |
| 8056 |
if (!FnAA) |
0 |
8056 |
if (!FnAA) |
0 |
| 8057 |
return indicatePessimisticFixpoint(); |
0 |
8057 |
return indicatePessimisticFixpoint(); |
0 |
| 8058 |
return clampStateAndIndicateChange(getState(), FnAA->getState()); |
0 |
8058 |
return clampStateAndIndicateChange(getState(), FnAA->getState()); |
0 |
| 8059 |
} |
--- |
8059 |
} |
--- |
| 8060 |
|
--- |
8060 |
|
--- |
| 8061 |
/// See AbstractAttribute::manifest(...). |
--- |
8061 |
/// See AbstractAttribute::manifest(...). |
--- |
| 8062 |
ChangeStatus manifest(Attributor &A) override { |
0 |
8062 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 8063 |
// TODO: Deduplicate this with AAMemoryBehaviorFunction. |
--- |
8063 |
// TODO: Deduplicate this with AAMemoryBehaviorFunction. |
--- |
| 8064 |
CallBase &CB = cast(getAnchorValue()); |
0 |
8064 |
CallBase &CB = cast(getAnchorValue()); |
0 |
| 8065 |
MemoryEffects ME = MemoryEffects::unknown(); |
0 |
8065 |
MemoryEffects ME = MemoryEffects::unknown(); |
0 |
| 8066 |
if (isAssumedReadNone()) |
0 |
8066 |
if (isAssumedReadNone()) |
0 |
| 8067 |
ME = MemoryEffects::none(); |
0 |
8067 |
ME = MemoryEffects::none(); |
0 |
| 8068 |
else if (isAssumedReadOnly()) |
0 |
8068 |
else if (isAssumedReadOnly()) |
0 |
| 8069 |
ME = MemoryEffects::readOnly(); |
0 |
8069 |
ME = MemoryEffects::readOnly(); |
0 |
| 8070 |
else if (isAssumedWriteOnly()) |
0 |
8070 |
else if (isAssumedWriteOnly()) |
0 |
| 8071 |
ME = MemoryEffects::writeOnly(); |
0 |
8071 |
ME = MemoryEffects::writeOnly(); |
0 |
| 8072 |
|
--- |
8072 |
|
--- |
| 8073 |
A.removeAttrs(getIRPosition(), AttrKinds); |
0 |
8073 |
A.removeAttrs(getIRPosition(), AttrKinds); |
0 |
| 8074 |
return A.manifestAttrs( |
0 |
8074 |
return A.manifestAttrs( |
0 |
| 8075 |
getIRPosition(), Attribute::getWithMemoryEffects(CB.getContext(), ME)); |
0 |
8075 |
getIRPosition(), Attribute::getWithMemoryEffects(CB.getContext(), ME)); |
0 |
| 8076 |
} |
--- |
8076 |
} |
--- |
| 8077 |
|
--- |
8077 |
|
--- |
| 8078 |
/// See AbstractAttribute::trackStatistics() |
--- |
8078 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 8079 |
void trackStatistics() const override { |
0 |
8079 |
void trackStatistics() const override { |
0 |
| 8080 |
if (isAssumedReadNone()) |
0 |
8080 |
if (isAssumedReadNone()) |
0 |
| 8081 |
STATS_DECLTRACK_CS_ATTR(readnone) |
0 |
8081 |
STATS_DECLTRACK_CS_ATTR(readnone) |
0 |
| 8082 |
else if (isAssumedReadOnly()) |
0 |
8082 |
else if (isAssumedReadOnly()) |
0 |
| 8083 |
STATS_DECLTRACK_CS_ATTR(readonly) |
0 |
8083 |
STATS_DECLTRACK_CS_ATTR(readonly) |
0 |
| 8084 |
else if (isAssumedWriteOnly()) |
0 |
8084 |
else if (isAssumedWriteOnly()) |
0 |
| 8085 |
STATS_DECLTRACK_CS_ATTR(writeonly) |
0 |
8085 |
STATS_DECLTRACK_CS_ATTR(writeonly) |
0 |
| 8086 |
} |
0 |
8086 |
} |
0 |
| 8087 |
}; |
--- |
8087 |
}; |
--- |
| 8088 |
|
--- |
8088 |
|
--- |
| 8089 |
ChangeStatus AAMemoryBehaviorFunction::updateImpl(Attributor &A) { |
0 |
8089 |
ChangeStatus AAMemoryBehaviorFunction::updateImpl(Attributor &A) { |
0 |
| 8090 |
|
--- |
8090 |
|
--- |
| 8091 |
// The current assumed state used to determine a change. |
--- |
8091 |
// The current assumed state used to determine a change. |
--- |
| 8092 |
auto AssumedState = getAssumed(); |
0 |
8092 |
auto AssumedState = getAssumed(); |
0 |
| 8093 |
|
--- |
8093 |
|
--- |
| 8094 |
auto CheckRWInst = [&](Instruction &I) { |
0 |
8094 |
auto CheckRWInst = [&](Instruction &I) { |
0 |
| 8095 |
// If the instruction has an own memory behavior state, use it to restrict |
--- |
8095 |
// If the instruction has an own memory behavior state, use it to restrict |
--- |
| 8096 |
// the local state. No further analysis is required as the other memory |
--- |
8096 |
// the local state. No further analysis is required as the other memory |
--- |
| 8097 |
// state is as optimistic as it gets. |
--- |
8097 |
// state is as optimistic as it gets. |
--- |
| 8098 |
if (const auto *CB = dyn_cast(&I)) { |
0 |
8098 |
if (const auto *CB = dyn_cast(&I)) { |
0 |
| 8099 |
const auto *MemBehaviorAA = A.getAAFor( |
0 |
8099 |
const auto *MemBehaviorAA = A.getAAFor( |
0 |
| 8100 |
*this, IRPosition::callsite_function(*CB), DepClassTy::REQUIRED); |
0 |
8100 |
*this, IRPosition::callsite_function(*CB), DepClassTy::REQUIRED); |
0 |
| 8101 |
if (MemBehaviorAA) { |
0 |
8101 |
if (MemBehaviorAA) { |
0 |
| 8102 |
intersectAssumedBits(MemBehaviorAA->getAssumed()); |
0 |
8102 |
intersectAssumedBits(MemBehaviorAA->getAssumed()); |
0 |
| 8103 |
return !isAtFixpoint(); |
0 |
8103 |
return !isAtFixpoint(); |
0 |
| 8104 |
} |
--- |
8104 |
} |
--- |
| 8105 |
} |
--- |
8105 |
} |
--- |
| 8106 |
|
--- |
8106 |
|
--- |
| 8107 |
// Remove access kind modifiers if necessary. |
--- |
8107 |
// Remove access kind modifiers if necessary. |
--- |
| 8108 |
if (I.mayReadFromMemory()) |
0 |
8108 |
if (I.mayReadFromMemory()) |
0 |
| 8109 |
removeAssumedBits(NO_READS); |
0 |
8109 |
removeAssumedBits(NO_READS); |
0 |
| 8110 |
if (I.mayWriteToMemory()) |
0 |
8110 |
if (I.mayWriteToMemory()) |
0 |
| 8111 |
removeAssumedBits(NO_WRITES); |
0 |
8111 |
removeAssumedBits(NO_WRITES); |
0 |
| 8112 |
return !isAtFixpoint(); |
0 |
8112 |
return !isAtFixpoint(); |
0 |
| 8113 |
}; |
0 |
8113 |
}; |
0 |
| 8114 |
|
--- |
8114 |
|
--- |
| 8115 |
bool UsedAssumedInformation = false; |
0 |
8115 |
bool UsedAssumedInformation = false; |
0 |
| 8116 |
if (!A.checkForAllReadWriteInstructions(CheckRWInst, *this, |
0 |
8116 |
if (!A.checkForAllReadWriteInstructions(CheckRWInst, *this, |
0 |
| 8117 |
UsedAssumedInformation)) |
--- |
8117 |
UsedAssumedInformation)) |
--- |
| 8118 |
return indicatePessimisticFixpoint(); |
0 |
8118 |
return indicatePessimisticFixpoint(); |
0 |
| 8119 |
|
--- |
8119 |
|
--- |
| 8120 |
return (AssumedState != getAssumed()) ? ChangeStatus::CHANGED |
0 |
8120 |
return (AssumedState != getAssumed()) ? ChangeStatus::CHANGED |
0 |
| 8121 |
: ChangeStatus::UNCHANGED; |
0 |
8121 |
: ChangeStatus::UNCHANGED; |
0 |
| 8122 |
} |
--- |
8122 |
} |
--- |
| 8123 |
|
--- |
8123 |
|
--- |
| 8124 |
ChangeStatus AAMemoryBehaviorFloating::updateImpl(Attributor &A) { |
0 |
8124 |
ChangeStatus AAMemoryBehaviorFloating::updateImpl(Attributor &A) { |
0 |
| 8125 |
|
--- |
8125 |
|
--- |
| 8126 |
const IRPosition &IRP = getIRPosition(); |
0 |
8126 |
const IRPosition &IRP = getIRPosition(); |
0 |
| 8127 |
const IRPosition &FnPos = IRPosition::function_scope(IRP); |
0 |
8127 |
const IRPosition &FnPos = IRPosition::function_scope(IRP); |
0 |
| 8128 |
AAMemoryBehavior::StateType &S = getState(); |
0 |
8128 |
AAMemoryBehavior::StateType &S = getState(); |
0 |
| 8129 |
|
--- |
8129 |
|
--- |
| 8130 |
// First, check the function scope. We take the known information and we avoid |
--- |
8130 |
// First, check the function scope. We take the known information and we avoid |
--- |
| 8131 |
// work if the assumed information implies the current assumed information for |
--- |
8131 |
// work if the assumed information implies the current assumed information for |
--- |
| 8132 |
// this attribute. This is a valid for all but byval arguments. |
--- |
8132 |
// this attribute. This is a valid for all but byval arguments. |
--- |
| 8133 |
Argument *Arg = IRP.getAssociatedArgument(); |
0 |
8133 |
Argument *Arg = IRP.getAssociatedArgument(); |
0 |
| 8134 |
AAMemoryBehavior::base_t FnMemAssumedState = |
0 |
8134 |
AAMemoryBehavior::base_t FnMemAssumedState = |
0 |
| 8135 |
AAMemoryBehavior::StateType::getWorstState(); |
--- |
8135 |
AAMemoryBehavior::StateType::getWorstState(); |
--- |
| 8136 |
if (!Arg || !Arg->hasByValAttr()) { |
0 |
8136 |
if (!Arg || !Arg->hasByValAttr()) { |
0 |
| 8137 |
const auto *FnMemAA = |
--- |
8137 |
const auto *FnMemAA = |
--- |
| 8138 |
A.getAAFor(*this, FnPos, DepClassTy::OPTIONAL); |
0 |
8138 |
A.getAAFor(*this, FnPos, DepClassTy::OPTIONAL); |
0 |
| 8139 |
if (FnMemAA) { |
0 |
8139 |
if (FnMemAA) { |
0 |
| 8140 |
FnMemAssumedState = FnMemAA->getAssumed(); |
0 |
8140 |
FnMemAssumedState = FnMemAA->getAssumed(); |
0 |
| 8141 |
S.addKnownBits(FnMemAA->getKnown()); |
0 |
8141 |
S.addKnownBits(FnMemAA->getKnown()); |
0 |
| 8142 |
if ((S.getAssumed() & FnMemAA->getAssumed()) == S.getAssumed()) |
0 |
8142 |
if ((S.getAssumed() & FnMemAA->getAssumed()) == S.getAssumed()) |
0 |
| 8143 |
return ChangeStatus::UNCHANGED; |
0 |
8143 |
return ChangeStatus::UNCHANGED; |
0 |
| 8144 |
} |
--- |
8144 |
} |
--- |
| 8145 |
} |
--- |
8145 |
} |
--- |
| 8146 |
|
--- |
8146 |
|
--- |
| 8147 |
// The current assumed state used to determine a change. |
--- |
8147 |
// The current assumed state used to determine a change. |
--- |
| 8148 |
auto AssumedState = S.getAssumed(); |
0 |
8148 |
auto AssumedState = S.getAssumed(); |
0 |
| 8149 |
|
--- |
8149 |
|
--- |
| 8150 |
// Make sure the value is not captured (except through "return"), if |
--- |
8150 |
// Make sure the value is not captured (except through "return"), if |
--- |
| 8151 |
// it is, any information derived would be irrelevant anyway as we cannot |
--- |
8151 |
// it is, any information derived would be irrelevant anyway as we cannot |
--- |
| 8152 |
// check the potential aliases introduced by the capture. However, no need |
--- |
8152 |
// check the potential aliases introduced by the capture. However, no need |
--- |
| 8153 |
// to fall back to anythign less optimistic than the function state. |
--- |
8153 |
// to fall back to anythign less optimistic than the function state. |
--- |
| 8154 |
bool IsKnownNoCapture; |
--- |
8154 |
bool IsKnownNoCapture; |
--- |
| 8155 |
const AANoCapture *ArgNoCaptureAA = nullptr; |
0 |
8155 |
const AANoCapture *ArgNoCaptureAA = nullptr; |
0 |
| 8156 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
8156 |
bool IsAssumedNoCapture = AA::hasAssumedIRAttr( |
0 |
| 8157 |
A, this, IRP, DepClassTy::OPTIONAL, IsKnownNoCapture, false, |
--- |
8157 |
A, this, IRP, DepClassTy::OPTIONAL, IsKnownNoCapture, false, |
--- |
| 8158 |
&ArgNoCaptureAA); |
--- |
8158 |
&ArgNoCaptureAA); |
--- |
| 8159 |
|
--- |
8159 |
|
--- |
| 8160 |
if (!IsAssumedNoCapture && |
0 |
8160 |
if (!IsAssumedNoCapture && |
0 |
| 8161 |
(!ArgNoCaptureAA || !ArgNoCaptureAA->isAssumedNoCaptureMaybeReturned())) { |
0 |
8161 |
(!ArgNoCaptureAA || !ArgNoCaptureAA->isAssumedNoCaptureMaybeReturned())) { |
0 |
| 8162 |
S.intersectAssumedBits(FnMemAssumedState); |
0 |
8162 |
S.intersectAssumedBits(FnMemAssumedState); |
0 |
| 8163 |
return (AssumedState != getAssumed()) ? ChangeStatus::CHANGED |
0 |
8163 |
return (AssumedState != getAssumed()) ? ChangeStatus::CHANGED |
0 |
| 8164 |
: ChangeStatus::UNCHANGED; |
0 |
8164 |
: ChangeStatus::UNCHANGED; |
0 |
| 8165 |
} |
--- |
8165 |
} |
--- |
| 8166 |
|
--- |
8166 |
|
--- |
| 8167 |
// Visit and expand uses until all are analyzed or a fixpoint is reached. |
--- |
8167 |
// Visit and expand uses until all are analyzed or a fixpoint is reached. |
--- |
| 8168 |
auto UsePred = [&](const Use &U, bool &Follow) -> bool { |
0 |
8168 |
auto UsePred = [&](const Use &U, bool &Follow) -> bool { |
0 |
| 8169 |
Instruction *UserI = cast(U.getUser()); |
0 |
8169 |
Instruction *UserI = cast(U.getUser()); |
0 |
| 8170 |
LLVM_DEBUG(dbgs() << "[AAMemoryBehavior] Use: " << *U << " in " << *UserI |
0 |
8170 |
LLVM_DEBUG(dbgs() << "[AAMemoryBehavior] Use: " << *U << " in " << *UserI |
0 |
| 8171 |
<< " \n"); |
--- |
8171 |
<< " \n"); |
--- |
| 8172 |
|
--- |
8172 |
|
--- |
| 8173 |
// Droppable users, e.g., llvm::assume does not actually perform any action. |
--- |
8173 |
// Droppable users, e.g., llvm::assume does not actually perform any action. |
--- |
| 8174 |
if (UserI->isDroppable()) |
0 |
8174 |
if (UserI->isDroppable()) |
0 |
| 8175 |
return true; |
0 |
8175 |
return true; |
0 |
| 8176 |
|
--- |
8176 |
|
--- |
| 8177 |
// Check if the users of UserI should also be visited. |
--- |
8177 |
// Check if the users of UserI should also be visited. |
--- |
| 8178 |
Follow = followUsersOfUseIn(A, U, UserI); |
0 |
8178 |
Follow = followUsersOfUseIn(A, U, UserI); |
0 |
| 8179 |
|
--- |
8179 |
|
--- |
| 8180 |
// If UserI might touch memory we analyze the use in detail. |
--- |
8180 |
// If UserI might touch memory we analyze the use in detail. |
--- |
| 8181 |
if (UserI->mayReadOrWriteMemory()) |
0 |
8181 |
if (UserI->mayReadOrWriteMemory()) |
0 |
| 8182 |
analyzeUseIn(A, U, UserI); |
0 |
8182 |
analyzeUseIn(A, U, UserI); |
0 |
| 8183 |
|
--- |
8183 |
|
--- |
| 8184 |
return !isAtFixpoint(); |
0 |
8184 |
return !isAtFixpoint(); |
0 |
| 8185 |
}; |
0 |
8185 |
}; |
0 |
| 8186 |
|
--- |
8186 |
|
--- |
| 8187 |
if (!A.checkForAllUses(UsePred, *this, getAssociatedValue())) |
0 |
8187 |
if (!A.checkForAllUses(UsePred, *this, getAssociatedValue())) |
0 |
| 8188 |
return indicatePessimisticFixpoint(); |
0 |
8188 |
return indicatePessimisticFixpoint(); |
0 |
| 8189 |
|
--- |
8189 |
|
--- |
| 8190 |
return (AssumedState != getAssumed()) ? ChangeStatus::CHANGED |
0 |
8190 |
return (AssumedState != getAssumed()) ? ChangeStatus::CHANGED |
0 |
| 8191 |
: ChangeStatus::UNCHANGED; |
0 |
8191 |
: ChangeStatus::UNCHANGED; |
0 |
| 8192 |
} |
--- |
8192 |
} |
--- |
| 8193 |
|
--- |
8193 |
|
--- |
| 8194 |
bool AAMemoryBehaviorFloating::followUsersOfUseIn(Attributor &A, const Use &U, |
0 |
8194 |
bool AAMemoryBehaviorFloating::followUsersOfUseIn(Attributor &A, const Use &U, |
0 |
| 8195 |
const Instruction *UserI) { |
--- |
8195 |
const Instruction *UserI) { |
--- |
| 8196 |
// The loaded value is unrelated to the pointer argument, no need to |
--- |
8196 |
// The loaded value is unrelated to the pointer argument, no need to |
--- |
| 8197 |
// follow the users of the load. |
--- |
8197 |
// follow the users of the load. |
--- |
| 8198 |
if (isa(UserI) || isa(UserI)) |
0 |
8198 |
if (isa(UserI) || isa(UserI)) |
0 |
| 8199 |
return false; |
0 |
8199 |
return false; |
0 |
| 8200 |
|
--- |
8200 |
|
--- |
| 8201 |
// By default we follow all uses assuming UserI might leak information on U, |
--- |
8201 |
// By default we follow all uses assuming UserI might leak information on U, |
--- |
| 8202 |
// we have special handling for call sites operands though. |
--- |
8202 |
// we have special handling for call sites operands though. |
--- |
| 8203 |
const auto *CB = dyn_cast(UserI); |
0 |
8203 |
const auto *CB = dyn_cast(UserI); |
0 |
| 8204 |
if (!CB || !CB->isArgOperand(&U)) |
0 |
8204 |
if (!CB || !CB->isArgOperand(&U)) |
0 |
| 8205 |
return true; |
0 |
8205 |
return true; |
0 |
| 8206 |
|
--- |
8206 |
|
--- |
| 8207 |
// If the use is a call argument known not to be captured, the users of |
--- |
8207 |
// If the use is a call argument known not to be captured, the users of |
--- |
| 8208 |
// the call do not need to be visited because they have to be unrelated to |
--- |
8208 |
// the call do not need to be visited because they have to be unrelated to |
--- |
| 8209 |
// the input. Note that this check is not trivial even though we disallow |
--- |
8209 |
// the input. Note that this check is not trivial even though we disallow |
--- |
| 8210 |
// general capturing of the underlying argument. The reason is that the |
--- |
8210 |
// general capturing of the underlying argument. The reason is that the |
--- |
| 8211 |
// call might the argument "through return", which we allow and for which we |
--- |
8211 |
// call might the argument "through return", which we allow and for which we |
--- |
| 8212 |
// need to check call users. |
--- |
8212 |
// need to check call users. |
--- |
| 8213 |
if (U.get()->getType()->isPointerTy()) { |
0 |
8213 |
if (U.get()->getType()->isPointerTy()) { |
0 |
| 8214 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
8214 |
unsigned ArgNo = CB->getArgOperandNo(&U); |
0 |
| 8215 |
bool IsKnownNoCapture; |
--- |
8215 |
bool IsKnownNoCapture; |
--- |
| 8216 |
return !AA::hasAssumedIRAttr( |
0 |
8216 |
return !AA::hasAssumedIRAttr( |
0 |
| 8217 |
A, this, IRPosition::callsite_argument(*CB, ArgNo), |
0 |
8217 |
A, this, IRPosition::callsite_argument(*CB, ArgNo), |
0 |
| 8218 |
DepClassTy::OPTIONAL, IsKnownNoCapture); |
0 |
8218 |
DepClassTy::OPTIONAL, IsKnownNoCapture); |
0 |
| 8219 |
} |
--- |
8219 |
} |
--- |
| 8220 |
|
--- |
8220 |
|
--- |
| 8221 |
return true; |
0 |
8221 |
return true; |
0 |
| 8222 |
} |
--- |
8222 |
} |
--- |
| 8223 |
|
--- |
8223 |
|
--- |
| 8224 |
void AAMemoryBehaviorFloating::analyzeUseIn(Attributor &A, const Use &U, |
0 |
8224 |
void AAMemoryBehaviorFloating::analyzeUseIn(Attributor &A, const Use &U, |
0 |
| 8225 |
const Instruction *UserI) { |
--- |
8225 |
const Instruction *UserI) { |
--- |
| 8226 |
assert(UserI->mayReadOrWriteMemory()); |
0 |
8226 |
assert(UserI->mayReadOrWriteMemory()); |
0 |
| 8227 |
|
--- |
8227 |
|
--- |
| 8228 |
switch (UserI->getOpcode()) { |
0 |
8228 |
switch (UserI->getOpcode()) { |
0 |
| 8229 |
default: |
0 |
8229 |
default: |
0 |
| 8230 |
// TODO: Handle all atomics and other side-effect operations we know of. |
--- |
8230 |
// TODO: Handle all atomics and other side-effect operations we know of. |
--- |
| 8231 |
break; |
0 |
8231 |
break; |
0 |
| 8232 |
case Instruction::Load: |
0 |
8232 |
case Instruction::Load: |
0 |
| 8233 |
// Loads cause the NO_READS property to disappear. |
--- |
8233 |
// Loads cause the NO_READS property to disappear. |
--- |
| 8234 |
removeAssumedBits(NO_READS); |
0 |
8234 |
removeAssumedBits(NO_READS); |
0 |
| 8235 |
return; |
0 |
8235 |
return; |
0 |
| 8236 |
|
--- |
8236 |
|
--- |
| 8237 |
case Instruction::Store: |
0 |
8237 |
case Instruction::Store: |
0 |
| 8238 |
// Stores cause the NO_WRITES property to disappear if the use is the |
--- |
8238 |
// Stores cause the NO_WRITES property to disappear if the use is the |
--- |
| 8239 |
// pointer operand. Note that while capturing was taken care of somewhere |
--- |
8239 |
// pointer operand. Note that while capturing was taken care of somewhere |
--- |
| 8240 |
// else we need to deal with stores of the value that is not looked through. |
--- |
8240 |
// else we need to deal with stores of the value that is not looked through. |
--- |
| 8241 |
if (cast(UserI)->getPointerOperand() == U.get()) |
0 |
8241 |
if (cast(UserI)->getPointerOperand() == U.get()) |
0 |
| 8242 |
removeAssumedBits(NO_WRITES); |
0 |
8242 |
removeAssumedBits(NO_WRITES); |
0 |
| 8243 |
else |
--- |
8243 |
else |
--- |
| 8244 |
indicatePessimisticFixpoint(); |
0 |
8244 |
indicatePessimisticFixpoint(); |
0 |
| 8245 |
return; |
0 |
8245 |
return; |
0 |
| 8246 |
|
--- |
8246 |
|
--- |
| 8247 |
case Instruction::Call: |
0 |
8247 |
case Instruction::Call: |
0 |
| 8248 |
case Instruction::CallBr: |
--- |
8248 |
case Instruction::CallBr: |
--- |
| 8249 |
case Instruction::Invoke: { |
--- |
8249 |
case Instruction::Invoke: { |
--- |
| 8250 |
// For call sites we look at the argument memory behavior attribute (this |
--- |
8250 |
// For call sites we look at the argument memory behavior attribute (this |
--- |
| 8251 |
// could be recursive!) in order to restrict our own state. |
--- |
8251 |
// could be recursive!) in order to restrict our own state. |
--- |
| 8252 |
const auto *CB = cast(UserI); |
0 |
8252 |
const auto *CB = cast(UserI); |
0 |
| 8253 |
|
--- |
8253 |
|
--- |
| 8254 |
// Give up on operand bundles. |
--- |
8254 |
// Give up on operand bundles. |
--- |
| 8255 |
if (CB->isBundleOperand(&U)) { |
0 |
8255 |
if (CB->isBundleOperand(&U)) { |
0 |
| 8256 |
indicatePessimisticFixpoint(); |
0 |
8256 |
indicatePessimisticFixpoint(); |
0 |
| 8257 |
return; |
0 |
8257 |
return; |
0 |
| 8258 |
} |
--- |
8258 |
} |
--- |
| 8259 |
|
--- |
8259 |
|
--- |
| 8260 |
// Calling a function does read the function pointer, maybe write it if the |
--- |
8260 |
// Calling a function does read the function pointer, maybe write it if the |
--- |
| 8261 |
// function is self-modifying. |
--- |
8261 |
// function is self-modifying. |
--- |
| 8262 |
if (CB->isCallee(&U)) { |
0 |
8262 |
if (CB->isCallee(&U)) { |
0 |
| 8263 |
removeAssumedBits(NO_READS); |
0 |
8263 |
removeAssumedBits(NO_READS); |
0 |
| 8264 |
break; |
0 |
8264 |
break; |
0 |
| 8265 |
} |
--- |
8265 |
} |
--- |
| 8266 |
|
--- |
8266 |
|
--- |
| 8267 |
// Adjust the possible access behavior based on the information on the |
--- |
8267 |
// Adjust the possible access behavior based on the information on the |
--- |
| 8268 |
// argument. |
--- |
8268 |
// argument. |
--- |
| 8269 |
IRPosition Pos; |
0 |
8269 |
IRPosition Pos; |
0 |
| 8270 |
if (U.get()->getType()->isPointerTy()) |
0 |
8270 |
if (U.get()->getType()->isPointerTy()) |
0 |
| 8271 |
Pos = IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U)); |
0 |
8271 |
Pos = IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U)); |
0 |
| 8272 |
else |
--- |
8272 |
else |
--- |
| 8273 |
Pos = IRPosition::callsite_function(*CB); |
0 |
8273 |
Pos = IRPosition::callsite_function(*CB); |
0 |
| 8274 |
const auto *MemBehaviorAA = |
--- |
8274 |
const auto *MemBehaviorAA = |
--- |
| 8275 |
A.getAAFor(*this, Pos, DepClassTy::OPTIONAL); |
0 |
8275 |
A.getAAFor(*this, Pos, DepClassTy::OPTIONAL); |
0 |
| 8276 |
if (!MemBehaviorAA) |
0 |
8276 |
if (!MemBehaviorAA) |
0 |
| 8277 |
break; |
0 |
8277 |
break; |
0 |
| 8278 |
// "assumed" has at most the same bits as the MemBehaviorAA assumed |
--- |
8278 |
// "assumed" has at most the same bits as the MemBehaviorAA assumed |
--- |
| 8279 |
// and at least "known". |
--- |
8279 |
// and at least "known". |
--- |
| 8280 |
intersectAssumedBits(MemBehaviorAA->getAssumed()); |
0 |
8280 |
intersectAssumedBits(MemBehaviorAA->getAssumed()); |
0 |
| 8281 |
return; |
0 |
8281 |
return; |
0 |
| 8282 |
} |
--- |
8282 |
} |
--- |
| 8283 |
}; |
--- |
8283 |
}; |
--- |
| 8284 |
|
--- |
8284 |
|
--- |
| 8285 |
// Generally, look at the "may-properties" and adjust the assumed state if we |
--- |
8285 |
// Generally, look at the "may-properties" and adjust the assumed state if we |
--- |
| 8286 |
// did not trigger special handling before. |
--- |
8286 |
// did not trigger special handling before. |
--- |
| 8287 |
if (UserI->mayReadFromMemory()) |
0 |
8287 |
if (UserI->mayReadFromMemory()) |
0 |
| 8288 |
removeAssumedBits(NO_READS); |
0 |
8288 |
removeAssumedBits(NO_READS); |
0 |
| 8289 |
if (UserI->mayWriteToMemory()) |
0 |
8289 |
if (UserI->mayWriteToMemory()) |
0 |
| 8290 |
removeAssumedBits(NO_WRITES); |
0 |
8290 |
removeAssumedBits(NO_WRITES); |
0 |
| 8291 |
} |
--- |
8291 |
} |
--- |
| 8292 |
} // namespace |
--- |
8292 |
} // namespace |
--- |
| 8293 |
|
--- |
8293 |
|
--- |
| 8294 |
/// -------------------- Memory Locations Attributes --------------------------- |
--- |
8294 |
/// -------------------- Memory Locations Attributes --------------------------- |
--- |
| 8295 |
/// Includes read-none, argmemonly, inaccessiblememonly, |
--- |
8295 |
/// Includes read-none, argmemonly, inaccessiblememonly, |
--- |
| 8296 |
/// inaccessiblememorargmemonly |
--- |
8296 |
/// inaccessiblememorargmemonly |
--- |
| 8297 |
/// ---------------------------------------------------------------------------- |
--- |
8297 |
/// ---------------------------------------------------------------------------- |
--- |
| 8298 |
|
--- |
8298 |
|
--- |
| 8299 |
std::string AAMemoryLocation::getMemoryLocationsAsStr( |
0 |
8299 |
std::string AAMemoryLocation::getMemoryLocationsAsStr( |
0 |
| 8300 |
AAMemoryLocation::MemoryLocationsKind MLK) { |
--- |
8300 |
AAMemoryLocation::MemoryLocationsKind MLK) { |
--- |
| 8301 |
if (0 == (MLK & AAMemoryLocation::NO_LOCATIONS)) |
0 |
8301 |
if (0 == (MLK & AAMemoryLocation::NO_LOCATIONS)) |
0 |
| 8302 |
return "all memory"; |
0 |
8302 |
return "all memory"; |
0 |
| 8303 |
if (MLK == AAMemoryLocation::NO_LOCATIONS) |
0 |
8303 |
if (MLK == AAMemoryLocation::NO_LOCATIONS) |
0 |
| 8304 |
return "no memory"; |
0 |
8304 |
return "no memory"; |
0 |
| 8305 |
std::string S = "memory:"; |
0 |
8305 |
std::string S = "memory:"; |
0 |
| 8306 |
if (0 == (MLK & AAMemoryLocation::NO_LOCAL_MEM)) |
0 |
8306 |
if (0 == (MLK & AAMemoryLocation::NO_LOCAL_MEM)) |
0 |
| 8307 |
S += "stack,"; |
0 |
8307 |
S += "stack,"; |
0 |
| 8308 |
if (0 == (MLK & AAMemoryLocation::NO_CONST_MEM)) |
0 |
8308 |
if (0 == (MLK & AAMemoryLocation::NO_CONST_MEM)) |
0 |
| 8309 |
S += "constant,"; |
0 |
8309 |
S += "constant,"; |
0 |
| 8310 |
if (0 == (MLK & AAMemoryLocation::NO_GLOBAL_INTERNAL_MEM)) |
0 |
8310 |
if (0 == (MLK & AAMemoryLocation::NO_GLOBAL_INTERNAL_MEM)) |
0 |
| 8311 |
S += "internal global,"; |
0 |
8311 |
S += "internal global,"; |
0 |
| 8312 |
if (0 == (MLK & AAMemoryLocation::NO_GLOBAL_EXTERNAL_MEM)) |
0 |
8312 |
if (0 == (MLK & AAMemoryLocation::NO_GLOBAL_EXTERNAL_MEM)) |
0 |
| 8313 |
S += "external global,"; |
0 |
8313 |
S += "external global,"; |
0 |
| 8314 |
if (0 == (MLK & AAMemoryLocation::NO_ARGUMENT_MEM)) |
0 |
8314 |
if (0 == (MLK & AAMemoryLocation::NO_ARGUMENT_MEM)) |
0 |
| 8315 |
S += "argument,"; |
0 |
8315 |
S += "argument,"; |
0 |
| 8316 |
if (0 == (MLK & AAMemoryLocation::NO_INACCESSIBLE_MEM)) |
0 |
8316 |
if (0 == (MLK & AAMemoryLocation::NO_INACCESSIBLE_MEM)) |
0 |
| 8317 |
S += "inaccessible,"; |
0 |
8317 |
S += "inaccessible,"; |
0 |
| 8318 |
if (0 == (MLK & AAMemoryLocation::NO_MALLOCED_MEM)) |
0 |
8318 |
if (0 == (MLK & AAMemoryLocation::NO_MALLOCED_MEM)) |
0 |
| 8319 |
S += "malloced,"; |
0 |
8319 |
S += "malloced,"; |
0 |
| 8320 |
if (0 == (MLK & AAMemoryLocation::NO_UNKOWN_MEM)) |
0 |
8320 |
if (0 == (MLK & AAMemoryLocation::NO_UNKOWN_MEM)) |
0 |
| 8321 |
S += "unknown,"; |
0 |
8321 |
S += "unknown,"; |
0 |
| 8322 |
S.pop_back(); |
0 |
8322 |
S.pop_back(); |
0 |
| 8323 |
return S; |
0 |
8323 |
return S; |
0 |
| 8324 |
} |
0 |
8324 |
} |
0 |
| 8325 |
|
--- |
8325 |
|
--- |
| 8326 |
namespace { |
--- |
8326 |
namespace { |
--- |
| 8327 |
struct AAMemoryLocationImpl : public AAMemoryLocation { |
--- |
8327 |
struct AAMemoryLocationImpl : public AAMemoryLocation { |
--- |
| 8328 |
|
--- |
8328 |
|
--- |
| 8329 |
AAMemoryLocationImpl(const IRPosition &IRP, Attributor &A) |
0 |
8329 |
AAMemoryLocationImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 8330 |
: AAMemoryLocation(IRP, A), Allocator(A.Allocator) { |
0 |
8330 |
: AAMemoryLocation(IRP, A), Allocator(A.Allocator) { |
0 |
| 8331 |
AccessKind2Accesses.fill(nullptr); |
0 |
8331 |
AccessKind2Accesses.fill(nullptr); |
0 |
| 8332 |
} |
0 |
8332 |
} |
0 |
| 8333 |
|
--- |
8333 |
|
--- |
| 8334 |
~AAMemoryLocationImpl() { |
0 |
8334 |
~AAMemoryLocationImpl() { |
0 |
| 8335 |
// The AccessSets are allocated via a BumpPtrAllocator, we call |
--- |
8335 |
// The AccessSets are allocated via a BumpPtrAllocator, we call |
--- |
| 8336 |
// the destructor manually. |
--- |
8336 |
// the destructor manually. |
--- |
| 8337 |
for (AccessSet *AS : AccessKind2Accesses) |
0 |
8337 |
for (AccessSet *AS : AccessKind2Accesses) |
0 |
| 8338 |
if (AS) |
0 |
8338 |
if (AS) |
0 |
| 8339 |
AS->~AccessSet(); |
0 |
8339 |
AS->~AccessSet(); |
0 |
| 8340 |
} |
0 |
8340 |
} |
0 |
| 8341 |
|
--- |
8341 |
|
--- |
| 8342 |
/// See AbstractAttribute::initialize(...). |
--- |
8342 |
/// See AbstractAttribute::initialize(...). |
--- |
| 8343 |
void initialize(Attributor &A) override { |
0 |
8343 |
void initialize(Attributor &A) override { |
0 |
| 8344 |
intersectAssumedBits(BEST_STATE); |
0 |
8344 |
intersectAssumedBits(BEST_STATE); |
0 |
| 8345 |
getKnownStateFromValue(A, getIRPosition(), getState()); |
0 |
8345 |
getKnownStateFromValue(A, getIRPosition(), getState()); |
0 |
| 8346 |
AAMemoryLocation::initialize(A); |
0 |
8346 |
AAMemoryLocation::initialize(A); |
0 |
| 8347 |
} |
0 |
8347 |
} |
0 |
| 8348 |
|
--- |
8348 |
|
--- |
| 8349 |
/// Return the memory behavior information encoded in the IR for \p IRP. |
--- |
8349 |
/// Return the memory behavior information encoded in the IR for \p IRP. |
--- |
| 8350 |
static void getKnownStateFromValue(Attributor &A, const IRPosition &IRP, |
0 |
8350 |
static void getKnownStateFromValue(Attributor &A, const IRPosition &IRP, |
0 |
| 8351 |
BitIntegerState &State, |
--- |
8351 |
BitIntegerState &State, |
--- |
| 8352 |
bool IgnoreSubsumingPositions = false) { |
--- |
8352 |
bool IgnoreSubsumingPositions = false) { |
--- |
| 8353 |
// For internal functions we ignore `argmemonly` and |
--- |
8353 |
// For internal functions we ignore `argmemonly` and |
--- |
| 8354 |
// `inaccessiblememorargmemonly` as we might break it via interprocedural |
--- |
8354 |
// `inaccessiblememorargmemonly` as we might break it via interprocedural |
--- |
| 8355 |
// constant propagation. It is unclear if this is the best way but it is |
--- |
8355 |
// constant propagation. It is unclear if this is the best way but it is |
--- |
| 8356 |
// unlikely this will cause real performance problems. If we are deriving |
--- |
8356 |
// unlikely this will cause real performance problems. If we are deriving |
--- |
| 8357 |
// attributes for the anchor function we even remove the attribute in |
--- |
8357 |
// attributes for the anchor function we even remove the attribute in |
--- |
| 8358 |
// addition to ignoring it. |
--- |
8358 |
// addition to ignoring it. |
--- |
| 8359 |
// TODO: A better way to handle this would be to add ~NO_GLOBAL_MEM / |
--- |
8359 |
// TODO: A better way to handle this would be to add ~NO_GLOBAL_MEM / |
--- |
| 8360 |
// MemoryEffects::Other as a possible location. |
--- |
8360 |
// MemoryEffects::Other as a possible location. |
--- |
| 8361 |
bool UseArgMemOnly = true; |
0 |
8361 |
bool UseArgMemOnly = true; |
0 |
| 8362 |
Function *AnchorFn = IRP.getAnchorScope(); |
0 |
8362 |
Function *AnchorFn = IRP.getAnchorScope(); |
0 |
| 8363 |
if (AnchorFn && A.isRunOn(*AnchorFn)) |
0 |
8363 |
if (AnchorFn && A.isRunOn(*AnchorFn)) |
0 |
| 8364 |
UseArgMemOnly = !AnchorFn->hasLocalLinkage(); |
0 |
8364 |
UseArgMemOnly = !AnchorFn->hasLocalLinkage(); |
0 |
| 8365 |
|
--- |
8365 |
|
--- |
| 8366 |
SmallVector Attrs; |
0 |
8366 |
SmallVector Attrs; |
0 |
| 8367 |
A.getAttrs(IRP, {Attribute::Memory}, Attrs, IgnoreSubsumingPositions); |
0 |
8367 |
A.getAttrs(IRP, {Attribute::Memory}, Attrs, IgnoreSubsumingPositions); |
0 |
| 8368 |
for (const Attribute &Attr : Attrs) { |
0 |
8368 |
for (const Attribute &Attr : Attrs) { |
0 |
| 8369 |
// TODO: We can map MemoryEffects to Attributor locations more precisely. |
--- |
8369 |
// TODO: We can map MemoryEffects to Attributor locations more precisely. |
--- |
| 8370 |
MemoryEffects ME = Attr.getMemoryEffects(); |
0 |
8370 |
MemoryEffects ME = Attr.getMemoryEffects(); |
0 |
| 8371 |
if (ME.doesNotAccessMemory()) { |
0 |
8371 |
if (ME.doesNotAccessMemory()) { |
0 |
| 8372 |
State.addKnownBits(NO_LOCAL_MEM | NO_CONST_MEM); |
0 |
8372 |
State.addKnownBits(NO_LOCAL_MEM | NO_CONST_MEM); |
0 |
| 8373 |
continue; |
0 |
8373 |
continue; |
0 |
| 8374 |
} |
--- |
8374 |
} |
--- |
| 8375 |
if (ME.onlyAccessesInaccessibleMem()) { |
0 |
8375 |
if (ME.onlyAccessesInaccessibleMem()) { |
0 |
| 8376 |
State.addKnownBits(inverseLocation(NO_INACCESSIBLE_MEM, true, true)); |
0 |
8376 |
State.addKnownBits(inverseLocation(NO_INACCESSIBLE_MEM, true, true)); |
0 |
| 8377 |
continue; |
0 |
8377 |
continue; |
0 |
| 8378 |
} |
--- |
8378 |
} |
--- |
| 8379 |
if (ME.onlyAccessesArgPointees()) { |
0 |
8379 |
if (ME.onlyAccessesArgPointees()) { |
0 |
| 8380 |
if (UseArgMemOnly) |
0 |
8380 |
if (UseArgMemOnly) |
0 |
| 8381 |
State.addKnownBits(inverseLocation(NO_ARGUMENT_MEM, true, true)); |
0 |
8381 |
State.addKnownBits(inverseLocation(NO_ARGUMENT_MEM, true, true)); |
0 |
| 8382 |
else { |
--- |
8382 |
else { |
--- |
| 8383 |
// Remove location information, only keep read/write info. |
--- |
8383 |
// Remove location information, only keep read/write info. |
--- |
| 8384 |
ME = MemoryEffects(ME.getModRef()); |
0 |
8384 |
ME = MemoryEffects(ME.getModRef()); |
0 |
| 8385 |
A.manifestAttrs(IRP, |
0 |
8385 |
A.manifestAttrs(IRP, |
0 |
| 8386 |
Attribute::getWithMemoryEffects( |
0 |
8386 |
Attribute::getWithMemoryEffects( |
0 |
| 8387 |
IRP.getAnchorValue().getContext(), ME), |
0 |
8387 |
IRP.getAnchorValue().getContext(), ME), |
0 |
| 8388 |
/*ForceReplace*/ true); |
--- |
8388 |
/*ForceReplace*/ true); |
--- |
| 8389 |
} |
--- |
8389 |
} |
--- |
| 8390 |
continue; |
0 |
8390 |
continue; |
0 |
| 8391 |
} |
--- |
8391 |
} |
--- |
| 8392 |
if (ME.onlyAccessesInaccessibleOrArgMem()) { |
0 |
8392 |
if (ME.onlyAccessesInaccessibleOrArgMem()) { |
0 |
| 8393 |
if (UseArgMemOnly) |
0 |
8393 |
if (UseArgMemOnly) |
0 |
| 8394 |
State.addKnownBits(inverseLocation( |
0 |
8394 |
State.addKnownBits(inverseLocation( |
0 |
| 8395 |
NO_INACCESSIBLE_MEM | NO_ARGUMENT_MEM, true, true)); |
--- |
8395 |
NO_INACCESSIBLE_MEM | NO_ARGUMENT_MEM, true, true)); |
--- |
| 8396 |
else { |
--- |
8396 |
else { |
--- |
| 8397 |
// Remove location information, only keep read/write info. |
--- |
8397 |
// Remove location information, only keep read/write info. |
--- |
| 8398 |
ME = MemoryEffects(ME.getModRef()); |
0 |
8398 |
ME = MemoryEffects(ME.getModRef()); |
0 |
| 8399 |
A.manifestAttrs(IRP, |
0 |
8399 |
A.manifestAttrs(IRP, |
0 |
| 8400 |
Attribute::getWithMemoryEffects( |
0 |
8400 |
Attribute::getWithMemoryEffects( |
0 |
| 8401 |
IRP.getAnchorValue().getContext(), ME), |
0 |
8401 |
IRP.getAnchorValue().getContext(), ME), |
0 |
| 8402 |
/*ForceReplace*/ true); |
--- |
8402 |
/*ForceReplace*/ true); |
--- |
| 8403 |
} |
--- |
8403 |
} |
--- |
| 8404 |
continue; |
0 |
8404 |
continue; |
0 |
| 8405 |
} |
--- |
8405 |
} |
--- |
| 8406 |
} |
--- |
8406 |
} |
--- |
| 8407 |
} |
0 |
8407 |
} |
0 |
| 8408 |
|
--- |
8408 |
|
--- |
| 8409 |
/// See AbstractAttribute::getDeducedAttributes(...). |
--- |
8409 |
/// See AbstractAttribute::getDeducedAttributes(...). |
--- |
| 8410 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
8410 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
| 8411 |
SmallVectorImpl &Attrs) const override { |
--- |
8411 |
SmallVectorImpl &Attrs) const override { |
--- |
| 8412 |
// TODO: We can map Attributor locations to MemoryEffects more precisely. |
--- |
8412 |
// TODO: We can map Attributor locations to MemoryEffects more precisely. |
--- |
| 8413 |
assert(Attrs.size() == 0); |
0 |
8413 |
assert(Attrs.size() == 0); |
0 |
| 8414 |
if (getIRPosition().getPositionKind() == IRPosition::IRP_FUNCTION) { |
0 |
8414 |
if (getIRPosition().getPositionKind() == IRPosition::IRP_FUNCTION) { |
0 |
| 8415 |
if (isAssumedReadNone()) |
0 |
8415 |
if (isAssumedReadNone()) |
0 |
| 8416 |
Attrs.push_back( |
0 |
8416 |
Attrs.push_back( |
0 |
| 8417 |
Attribute::getWithMemoryEffects(Ctx, MemoryEffects::none())); |
--- |
8417 |
Attribute::getWithMemoryEffects(Ctx, MemoryEffects::none())); |
--- |
| 8418 |
else if (isAssumedInaccessibleMemOnly()) |
0 |
8418 |
else if (isAssumedInaccessibleMemOnly()) |
0 |
| 8419 |
Attrs.push_back(Attribute::getWithMemoryEffects( |
0 |
8419 |
Attrs.push_back(Attribute::getWithMemoryEffects( |
0 |
| 8420 |
Ctx, MemoryEffects::inaccessibleMemOnly())); |
--- |
8420 |
Ctx, MemoryEffects::inaccessibleMemOnly())); |
--- |
| 8421 |
else if (isAssumedArgMemOnly()) |
0 |
8421 |
else if (isAssumedArgMemOnly()) |
0 |
| 8422 |
Attrs.push_back( |
0 |
8422 |
Attrs.push_back( |
0 |
| 8423 |
Attribute::getWithMemoryEffects(Ctx, MemoryEffects::argMemOnly())); |
--- |
8423 |
Attribute::getWithMemoryEffects(Ctx, MemoryEffects::argMemOnly())); |
--- |
| 8424 |
else if (isAssumedInaccessibleOrArgMemOnly()) |
0 |
8424 |
else if (isAssumedInaccessibleOrArgMemOnly()) |
0 |
| 8425 |
Attrs.push_back(Attribute::getWithMemoryEffects( |
0 |
8425 |
Attrs.push_back(Attribute::getWithMemoryEffects( |
0 |
| 8426 |
Ctx, MemoryEffects::inaccessibleOrArgMemOnly())); |
--- |
8426 |
Ctx, MemoryEffects::inaccessibleOrArgMemOnly())); |
--- |
| 8427 |
} |
--- |
8427 |
} |
--- |
| 8428 |
assert(Attrs.size() <= 1); |
0 |
8428 |
assert(Attrs.size() <= 1); |
0 |
| 8429 |
} |
0 |
8429 |
} |
0 |
| 8430 |
|
--- |
8430 |
|
--- |
| 8431 |
/// See AbstractAttribute::manifest(...). |
--- |
8431 |
/// See AbstractAttribute::manifest(...). |
--- |
| 8432 |
ChangeStatus manifest(Attributor &A) override { |
0 |
8432 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 8433 |
// TODO: If AAMemoryLocation and AAMemoryBehavior are merged, we could |
--- |
8433 |
// TODO: If AAMemoryLocation and AAMemoryBehavior are merged, we could |
--- |
| 8434 |
// provide per-location modref information here. |
--- |
8434 |
// provide per-location modref information here. |
--- |
| 8435 |
const IRPosition &IRP = getIRPosition(); |
0 |
8435 |
const IRPosition &IRP = getIRPosition(); |
0 |
| 8436 |
|
--- |
8436 |
|
--- |
| 8437 |
SmallVector DeducedAttrs; |
0 |
8437 |
SmallVector DeducedAttrs; |
0 |
| 8438 |
getDeducedAttributes(A, IRP.getAnchorValue().getContext(), DeducedAttrs); |
0 |
8438 |
getDeducedAttributes(A, IRP.getAnchorValue().getContext(), DeducedAttrs); |
0 |
| 8439 |
if (DeducedAttrs.size() != 1) |
0 |
8439 |
if (DeducedAttrs.size() != 1) |
0 |
| 8440 |
return ChangeStatus::UNCHANGED; |
0 |
8440 |
return ChangeStatus::UNCHANGED; |
0 |
| 8441 |
MemoryEffects ME = DeducedAttrs[0].getMemoryEffects(); |
0 |
8441 |
MemoryEffects ME = DeducedAttrs[0].getMemoryEffects(); |
0 |
| 8442 |
|
--- |
8442 |
|
--- |
| 8443 |
return A.manifestAttrs(IRP, Attribute::getWithMemoryEffects( |
0 |
8443 |
return A.manifestAttrs(IRP, Attribute::getWithMemoryEffects( |
0 |
| 8444 |
IRP.getAnchorValue().getContext(), ME)); |
0 |
8444 |
IRP.getAnchorValue().getContext(), ME)); |
0 |
| 8445 |
} |
0 |
8445 |
} |
0 |
| 8446 |
|
--- |
8446 |
|
--- |
| 8447 |
/// See AAMemoryLocation::checkForAllAccessesToMemoryKind(...). |
--- |
8447 |
/// See AAMemoryLocation::checkForAllAccessesToMemoryKind(...). |
--- |
| 8448 |
bool checkForAllAccessesToMemoryKind( |
0 |
8448 |
bool checkForAllAccessesToMemoryKind( |
0 |
| 8449 |
function_ref
| --- |
8449 |
function_ref
| --- |
| |
| 8450 |
MemoryLocationsKind)> |
--- |
8450 |
MemoryLocationsKind)> |
--- |
| 8451 |
Pred, |
--- |
8451 |
Pred, |
--- |
| 8452 |
MemoryLocationsKind RequestedMLK) const override { |
--- |
8452 |
MemoryLocationsKind RequestedMLK) const override { |
--- |
| 8453 |
if (!isValidState()) |
0 |
8453 |
if (!isValidState()) |
0 |
| 8454 |
return false; |
0 |
8454 |
return false; |
0 |
| 8455 |
|
--- |
8455 |
|
--- |
| 8456 |
MemoryLocationsKind AssumedMLK = getAssumedNotAccessedLocation(); |
0 |
8456 |
MemoryLocationsKind AssumedMLK = getAssumedNotAccessedLocation(); |
0 |
| 8457 |
if (AssumedMLK == NO_LOCATIONS) |
0 |
8457 |
if (AssumedMLK == NO_LOCATIONS) |
0 |
| 8458 |
return true; |
0 |
8458 |
return true; |
0 |
| 8459 |
|
--- |
8459 |
|
--- |
| 8460 |
unsigned Idx = 0; |
0 |
8460 |
unsigned Idx = 0; |
0 |
| 8461 |
for (MemoryLocationsKind CurMLK = 1; CurMLK < NO_LOCATIONS; |
0 |
8461 |
for (MemoryLocationsKind CurMLK = 1; CurMLK < NO_LOCATIONS; |
0 |
| 8462 |
CurMLK *= 2, ++Idx) { |
0 |
8462 |
CurMLK *= 2, ++Idx) { |
0 |
| 8463 |
if (CurMLK & RequestedMLK) |
0 |
8463 |
if (CurMLK & RequestedMLK) |
0 |
| 8464 |
continue; |
0 |
8464 |
continue; |
0 |
| 8465 |
|
--- |
8465 |
|
--- |
| 8466 |
if (const AccessSet *Accesses = AccessKind2Accesses[Idx]) |
0 |
8466 |
if (const AccessSet *Accesses = AccessKind2Accesses[Idx]) |
0 |
| 8467 |
for (const AccessInfo &AI : *Accesses) |
0 |
8467 |
for (const AccessInfo &AI : *Accesses) |
0 |
| 8468 |
if (!Pred(AI.I, AI.Ptr, AI.Kind, CurMLK)) |
0 |
8468 |
if (!Pred(AI.I, AI.Ptr, AI.Kind, CurMLK)) |
0 |
| 8469 |
return false; |
0 |
8469 |
return false; |
0 |
| 8470 |
} |
--- |
8470 |
} |
--- |
| 8471 |
|
--- |
8471 |
|
--- |
| 8472 |
return true; |
0 |
8472 |
return true; |
0 |
| 8473 |
} |
--- |
8473 |
} |
--- |
| 8474 |
|
--- |
8474 |
|
--- |
| 8475 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
8475 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
| 8476 |
// If we give up and indicate a pessimistic fixpoint this instruction will |
--- |
8476 |
// If we give up and indicate a pessimistic fixpoint this instruction will |
--- |
| 8477 |
// become an access for all potential access kinds: |
--- |
8477 |
// become an access for all potential access kinds: |
--- |
| 8478 |
// TODO: Add pointers for argmemonly and globals to improve the results of |
--- |
8478 |
// TODO: Add pointers for argmemonly and globals to improve the results of |
--- |
| 8479 |
// checkForAllAccessesToMemoryKind. |
--- |
8479 |
// checkForAllAccessesToMemoryKind. |
--- |
| 8480 |
bool Changed = false; |
0 |
8480 |
bool Changed = false; |
0 |
| 8481 |
MemoryLocationsKind KnownMLK = getKnown(); |
0 |
8481 |
MemoryLocationsKind KnownMLK = getKnown(); |
0 |
| 8482 |
Instruction *I = dyn_cast(&getAssociatedValue()); |
0 |
8482 |
Instruction *I = dyn_cast(&getAssociatedValue()); |
0 |
| 8483 |
for (MemoryLocationsKind CurMLK = 1; CurMLK < NO_LOCATIONS; CurMLK *= 2) |
0 |
8483 |
for (MemoryLocationsKind CurMLK = 1; CurMLK < NO_LOCATIONS; CurMLK *= 2) |
0 |
| 8484 |
if (!(CurMLK & KnownMLK)) |
0 |
8484 |
if (!(CurMLK & KnownMLK)) |
0 |
| 8485 |
updateStateAndAccessesMap(getState(), CurMLK, I, nullptr, Changed, |
0 |
8485 |
updateStateAndAccessesMap(getState(), CurMLK, I, nullptr, Changed, |
0 |
| 8486 |
getAccessKindFromInst(I)); |
--- |
8486 |
getAccessKindFromInst(I)); |
--- |
| 8487 |
return AAMemoryLocation::indicatePessimisticFixpoint(); |
0 |
8487 |
return AAMemoryLocation::indicatePessimisticFixpoint(); |
0 |
| 8488 |
} |
--- |
8488 |
} |
--- |
| 8489 |
|
--- |
8489 |
|
--- |
| 8490 |
protected: |
--- |
8490 |
protected: |
--- |
| 8491 |
/// Helper struct to tie together an instruction that has a read or write |
--- |
8491 |
/// Helper struct to tie together an instruction that has a read or write |
--- |
| 8492 |
/// effect with the pointer it accesses (if any). |
--- |
8492 |
/// effect with the pointer it accesses (if any). |
--- |
| 8493 |
struct AccessInfo { |
--- |
8493 |
struct AccessInfo { |
--- |
| 8494 |
|
--- |
8494 |
|
--- |
| 8495 |
/// The instruction that caused the access. |
--- |
8495 |
/// The instruction that caused the access. |
--- |
| 8496 |
const Instruction *I; |
--- |
8496 |
const Instruction *I; |
--- |
| 8497 |
|
--- |
8497 |
|
--- |
| 8498 |
/// The base pointer that is accessed, or null if unknown. |
--- |
8498 |
/// The base pointer that is accessed, or null if unknown. |
--- |
| 8499 |
const Value *Ptr; |
--- |
8499 |
const Value *Ptr; |
--- |
| 8500 |
|
--- |
8500 |
|
--- |
| 8501 |
/// The kind of access (read/write/read+write). |
--- |
8501 |
/// The kind of access (read/write/read+write). |
--- |
| 8502 |
AccessKind Kind; |
--- |
8502 |
AccessKind Kind; |
--- |
| 8503 |
|
--- |
8503 |
|
--- |
| 8504 |
bool operator==(const AccessInfo &RHS) const { |
0 |
8504 |
bool operator==(const AccessInfo &RHS) const { |
0 |
| 8505 |
return I == RHS.I && Ptr == RHS.Ptr && Kind == RHS.Kind; |
0 |
8505 |
return I == RHS.I && Ptr == RHS.Ptr && Kind == RHS.Kind; |
0 |
| 8506 |
} |
--- |
8506 |
} |
--- |
| 8507 |
bool operator()(const AccessInfo &LHS, const AccessInfo &RHS) const { |
0 |
8507 |
bool operator()(const AccessInfo &LHS, const AccessInfo &RHS) const { |
0 |
| 8508 |
if (LHS.I != RHS.I) |
0 |
8508 |
if (LHS.I != RHS.I) |
0 |
| 8509 |
return LHS.I < RHS.I; |
0 |
8509 |
return LHS.I < RHS.I; |
0 |
| 8510 |
if (LHS.Ptr != RHS.Ptr) |
0 |
8510 |
if (LHS.Ptr != RHS.Ptr) |
0 |
| 8511 |
return LHS.Ptr < RHS.Ptr; |
0 |
8511 |
return LHS.Ptr < RHS.Ptr; |
0 |
| 8512 |
if (LHS.Kind != RHS.Kind) |
0 |
8512 |
if (LHS.Kind != RHS.Kind) |
0 |
| 8513 |
return LHS.Kind < RHS.Kind; |
0 |
8513 |
return LHS.Kind < RHS.Kind; |
0 |
| 8514 |
return false; |
0 |
8514 |
return false; |
0 |
| 8515 |
} |
--- |
8515 |
} |
--- |
| 8516 |
}; |
--- |
8516 |
}; |
--- |
| 8517 |
|
--- |
8517 |
|
--- |
| 8518 |
/// Mapping from *single* memory location kinds, e.g., LOCAL_MEM with the |
--- |
8518 |
/// Mapping from *single* memory location kinds, e.g., LOCAL_MEM with the |
--- |
| 8519 |
/// value of NO_LOCAL_MEM, to the accesses encountered for this memory kind. |
--- |
8519 |
/// value of NO_LOCAL_MEM, to the accesses encountered for this memory kind. |
--- |
| 8520 |
using AccessSet = SmallSet; |
--- |
8520 |
using AccessSet = SmallSet; |
--- |
| 8521 |
std::array()> AccessKind2Accesses; |
--- |
8521 |
std::array()> AccessKind2Accesses; |
--- |
| 8522 |
|
--- |
8522 |
|
--- |
| 8523 |
/// Categorize the pointer arguments of CB that might access memory in |
--- |
8523 |
/// Categorize the pointer arguments of CB that might access memory in |
--- |
| 8524 |
/// AccessedLoc and update the state and access map accordingly. |
--- |
8524 |
/// AccessedLoc and update the state and access map accordingly. |
--- |
| 8525 |
void |
--- |
8525 |
void |
--- |
| 8526 |
categorizeArgumentPointerLocations(Attributor &A, CallBase &CB, |
--- |
8526 |
categorizeArgumentPointerLocations(Attributor &A, CallBase &CB, |
--- |
| 8527 |
AAMemoryLocation::StateType &AccessedLocs, |
--- |
8527 |
AAMemoryLocation::StateType &AccessedLocs, |
--- |
| 8528 |
bool &Changed); |
--- |
8528 |
bool &Changed); |
--- |
| 8529 |
|
--- |
8529 |
|
--- |
| 8530 |
/// Return the kind(s) of location that may be accessed by \p V. |
--- |
8530 |
/// Return the kind(s) of location that may be accessed by \p V. |
--- |
| 8531 |
AAMemoryLocation::MemoryLocationsKind |
--- |
8531 |
AAMemoryLocation::MemoryLocationsKind |
--- |
| 8532 |
categorizeAccessedLocations(Attributor &A, Instruction &I, bool &Changed); |
--- |
8532 |
categorizeAccessedLocations(Attributor &A, Instruction &I, bool &Changed); |
--- |
| 8533 |
|
--- |
8533 |
|
--- |
| 8534 |
/// Return the access kind as determined by \p I. |
--- |
8534 |
/// Return the access kind as determined by \p I. |
--- |
| 8535 |
AccessKind getAccessKindFromInst(const Instruction *I) { |
0 |
8535 |
AccessKind getAccessKindFromInst(const Instruction *I) { |
0 |
| 8536 |
AccessKind AK = READ_WRITE; |
0 |
8536 |
AccessKind AK = READ_WRITE; |
0 |
| 8537 |
if (I) { |
0 |
8537 |
if (I) { |
0 |
| 8538 |
AK = I->mayReadFromMemory() ? READ : NONE; |
0 |
8538 |
AK = I->mayReadFromMemory() ? READ : NONE; |
0 |
| 8539 |
AK = AccessKind(AK | (I->mayWriteToMemory() ? WRITE : NONE)); |
0 |
8539 |
AK = AccessKind(AK | (I->mayWriteToMemory() ? WRITE : NONE)); |
0 |
| 8540 |
} |
--- |
8540 |
} |
--- |
| 8541 |
return AK; |
0 |
8541 |
return AK; |
0 |
| 8542 |
} |
--- |
8542 |
} |
--- |
| 8543 |
|
--- |
8543 |
|
--- |
| 8544 |
/// Update the state \p State and the AccessKind2Accesses given that \p I is |
--- |
8544 |
/// Update the state \p State and the AccessKind2Accesses given that \p I is |
--- |
| 8545 |
/// an access of kind \p AK to a \p MLK memory location with the access |
--- |
8545 |
/// an access of kind \p AK to a \p MLK memory location with the access |
--- |
| 8546 |
/// pointer \p Ptr. |
--- |
8546 |
/// pointer \p Ptr. |
--- |
| 8547 |
void updateStateAndAccessesMap(AAMemoryLocation::StateType &State, |
0 |
8547 |
void updateStateAndAccessesMap(AAMemoryLocation::StateType &State, |
0 |
| 8548 |
MemoryLocationsKind MLK, const Instruction *I, |
--- |
8548 |
MemoryLocationsKind MLK, const Instruction *I, |
--- |
| 8549 |
const Value *Ptr, bool &Changed, |
--- |
8549 |
const Value *Ptr, bool &Changed, |
--- |
| 8550 |
AccessKind AK = READ_WRITE) { |
--- |
8550 |
AccessKind AK = READ_WRITE) { |
--- |
| 8551 |
|
--- |
8551 |
|
--- |
| 8552 |
assert(isPowerOf2_32(MLK) && "Expected a single location set!"); |
0 |
8552 |
assert(isPowerOf2_32(MLK) && "Expected a single location set!"); |
0 |
| 8553 |
auto *&Accesses = AccessKind2Accesses[llvm::Log2_32(MLK)]; |
0 |
8553 |
auto *&Accesses = AccessKind2Accesses[llvm::Log2_32(MLK)]; |
0 |
| 8554 |
if (!Accesses) |
0 |
8554 |
if (!Accesses) |
0 |
| 8555 |
Accesses = new (Allocator) AccessSet(); |
0 |
8555 |
Accesses = new (Allocator) AccessSet(); |
0 |
| 8556 |
Changed |= Accesses->insert(AccessInfo{I, Ptr, AK}).second; |
0 |
8556 |
Changed |= Accesses->insert(AccessInfo{I, Ptr, AK}).second; |
0 |
| 8557 |
if (MLK == NO_UNKOWN_MEM) |
0 |
8557 |
if (MLK == NO_UNKOWN_MEM) |
0 |
| 8558 |
MLK = NO_LOCATIONS; |
0 |
8558 |
MLK = NO_LOCATIONS; |
0 |
| 8559 |
State.removeAssumedBits(MLK); |
0 |
8559 |
State.removeAssumedBits(MLK); |
0 |
| 8560 |
} |
0 |
8560 |
} |
0 |
| 8561 |
|
--- |
8561 |
|
--- |
| 8562 |
/// Determine the underlying locations kinds for \p Ptr, e.g., globals or |
--- |
8562 |
/// Determine the underlying locations kinds for \p Ptr, e.g., globals or |
--- |
| 8563 |
/// arguments, and update the state and access map accordingly. |
--- |
8563 |
/// arguments, and update the state and access map accordingly. |
--- |
| 8564 |
void categorizePtrValue(Attributor &A, const Instruction &I, const Value &Ptr, |
--- |
8564 |
void categorizePtrValue(Attributor &A, const Instruction &I, const Value &Ptr, |
--- |
| 8565 |
AAMemoryLocation::StateType &State, bool &Changed, |
--- |
8565 |
AAMemoryLocation::StateType &State, bool &Changed, |
--- |
| 8566 |
unsigned AccessAS = 0); |
--- |
8566 |
unsigned AccessAS = 0); |
--- |
| 8567 |
|
--- |
8567 |
|
--- |
| 8568 |
/// Used to allocate access sets. |
--- |
8568 |
/// Used to allocate access sets. |
--- |
| 8569 |
BumpPtrAllocator &Allocator; |
--- |
8569 |
BumpPtrAllocator &Allocator; |
--- |
| 8570 |
}; |
--- |
8570 |
}; |
--- |
| 8571 |
|
--- |
8571 |
|
--- |
| 8572 |
void AAMemoryLocationImpl::categorizePtrValue( |
0 |
8572 |
void AAMemoryLocationImpl::categorizePtrValue( |
0 |
| 8573 |
Attributor &A, const Instruction &I, const Value &Ptr, |
--- |
8573 |
Attributor &A, const Instruction &I, const Value &Ptr, |
--- |
| 8574 |
AAMemoryLocation::StateType &State, bool &Changed, unsigned AccessAS) { |
--- |
8574 |
AAMemoryLocation::StateType &State, bool &Changed, unsigned AccessAS) { |
--- |
| 8575 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Categorize pointer locations for " |
0 |
8575 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Categorize pointer locations for " |
0 |
| 8576 |
<< Ptr << " [" |
--- |
8576 |
<< Ptr << " [" |
--- |
| 8577 |
<< getMemoryLocationsAsStr(State.getAssumed()) << "]\n"); |
--- |
8577 |
<< getMemoryLocationsAsStr(State.getAssumed()) << "]\n"); |
--- |
| 8578 |
|
--- |
8578 |
|
--- |
| 8579 |
auto Pred = [&](Value &Obj) { |
0 |
8579 |
auto Pred = [&](Value &Obj) { |
0 |
| 8580 |
unsigned ObjectAS = Obj.getType()->getPointerAddressSpace(); |
0 |
8580 |
unsigned ObjectAS = Obj.getType()->getPointerAddressSpace(); |
0 |
| 8581 |
// TODO: recognize the TBAA used for constant accesses. |
--- |
8581 |
// TODO: recognize the TBAA used for constant accesses. |
--- |
| 8582 |
MemoryLocationsKind MLK = NO_LOCATIONS; |
0 |
8582 |
MemoryLocationsKind MLK = NO_LOCATIONS; |
0 |
| 8583 |
|
--- |
8583 |
|
--- |
| 8584 |
// Filter accesses to constant (GPU) memory if we have an AS at the access |
--- |
8584 |
// Filter accesses to constant (GPU) memory if we have an AS at the access |
--- |
| 8585 |
// site or the object is known to actually have the associated AS. |
--- |
8585 |
// site or the object is known to actually have the associated AS. |
--- |
| 8586 |
if ((AccessAS == (unsigned)AA::GPUAddressSpace::Constant || |
0 |
8586 |
if ((AccessAS == (unsigned)AA::GPUAddressSpace::Constant || |
0 |
| 8587 |
(ObjectAS == (unsigned)AA::GPUAddressSpace::Constant && |
0 |
8587 |
(ObjectAS == (unsigned)AA::GPUAddressSpace::Constant && |
0 |
| 8588 |
isIdentifiedObject(&Obj))) && |
0 |
8588 |
isIdentifiedObject(&Obj))) && |
0 |
| 8589 |
AA::isGPU(*I.getModule())) |
0 |
8589 |
AA::isGPU(*I.getModule())) |
0 |
| 8590 |
return true; |
0 |
8590 |
return true; |
0 |
| 8591 |
|
--- |
8591 |
|
--- |
| 8592 |
if (isa(&Obj)) |
0 |
8592 |
if (isa(&Obj)) |
0 |
| 8593 |
return true; |
0 |
8593 |
return true; |
0 |
| 8594 |
if (isa(&Obj)) { |
0 |
8594 |
if (isa(&Obj)) { |
0 |
| 8595 |
// TODO: For now we do not treat byval arguments as local copies performed |
--- |
8595 |
// TODO: For now we do not treat byval arguments as local copies performed |
--- |
| 8596 |
// on the call edge, though, we should. To make that happen we need to |
--- |
8596 |
// on the call edge, though, we should. To make that happen we need to |
--- |
| 8597 |
// teach various passes, e.g., DSE, about the copy effect of a byval. That |
--- |
8597 |
// teach various passes, e.g., DSE, about the copy effect of a byval. That |
--- |
| 8598 |
// would also allow us to mark functions only accessing byval arguments as |
--- |
8598 |
// would also allow us to mark functions only accessing byval arguments as |
--- |
| 8599 |
// readnone again, arguably their accesses have no effect outside of the |
--- |
8599 |
// readnone again, arguably their accesses have no effect outside of the |
--- |
| 8600 |
// function, like accesses to allocas. |
--- |
8600 |
// function, like accesses to allocas. |
--- |
| 8601 |
MLK = NO_ARGUMENT_MEM; |
0 |
8601 |
MLK = NO_ARGUMENT_MEM; |
0 |
| 8602 |
} else if (auto *GV = dyn_cast(&Obj)) { |
0 |
8602 |
} else if (auto *GV = dyn_cast(&Obj)) { |
0 |
| 8603 |
// Reading constant memory is not treated as a read "effect" by the |
--- |
8603 |
// Reading constant memory is not treated as a read "effect" by the |
--- |
| 8604 |
// function attr pass so we won't neither. Constants defined by TBAA are |
--- |
8604 |
// function attr pass so we won't neither. Constants defined by TBAA are |
--- |
| 8605 |
// similar. (We know we do not write it because it is constant.) |
--- |
8605 |
// similar. (We know we do not write it because it is constant.) |
--- |
| 8606 |
if (auto *GVar = dyn_cast(GV)) |
0 |
8606 |
if (auto *GVar = dyn_cast(GV)) |
0 |
| 8607 |
if (GVar->isConstant()) |
0 |
8607 |
if (GVar->isConstant()) |
0 |
| 8608 |
return true; |
0 |
8608 |
return true; |
0 |
| 8609 |
|
--- |
8609 |
|
--- |
| 8610 |
if (GV->hasLocalLinkage()) |
0 |
8610 |
if (GV->hasLocalLinkage()) |
0 |
| 8611 |
MLK = NO_GLOBAL_INTERNAL_MEM; |
0 |
8611 |
MLK = NO_GLOBAL_INTERNAL_MEM; |
0 |
| 8612 |
else |
--- |
8612 |
else |
--- |
| 8613 |
MLK = NO_GLOBAL_EXTERNAL_MEM; |
0 |
8613 |
MLK = NO_GLOBAL_EXTERNAL_MEM; |
0 |
| 8614 |
} else if (isa(&Obj) && |
0 |
8614 |
} else if (isa(&Obj) && |
0 |
| 8615 |
(!NullPointerIsDefined(getAssociatedFunction(), AccessAS) || |
0 |
8615 |
(!NullPointerIsDefined(getAssociatedFunction(), AccessAS) || |
0 |
| 8616 |
!NullPointerIsDefined(getAssociatedFunction(), ObjectAS))) { |
0 |
8616 |
!NullPointerIsDefined(getAssociatedFunction(), ObjectAS))) { |
0 |
| 8617 |
return true; |
0 |
8617 |
return true; |
0 |
| 8618 |
} else if (isa(&Obj)) { |
0 |
8618 |
} else if (isa(&Obj)) { |
0 |
| 8619 |
MLK = NO_LOCAL_MEM; |
0 |
8619 |
MLK = NO_LOCAL_MEM; |
0 |
| 8620 |
} else if (const auto *CB = dyn_cast(&Obj)) { |
0 |
8620 |
} else if (const auto *CB = dyn_cast(&Obj)) { |
0 |
| 8621 |
bool IsKnownNoAlias; |
--- |
8621 |
bool IsKnownNoAlias; |
--- |
| 8622 |
if (AA::hasAssumedIRAttr( |
0 |
8622 |
if (AA::hasAssumedIRAttr( |
0 |
| 8623 |
A, this, IRPosition::callsite_returned(*CB), DepClassTy::OPTIONAL, |
0 |
8623 |
A, this, IRPosition::callsite_returned(*CB), DepClassTy::OPTIONAL, |
0 |
| 8624 |
IsKnownNoAlias)) |
--- |
8624 |
IsKnownNoAlias)) |
--- |
| 8625 |
MLK = NO_MALLOCED_MEM; |
0 |
8625 |
MLK = NO_MALLOCED_MEM; |
0 |
| 8626 |
else |
--- |
8626 |
else |
--- |
| 8627 |
MLK = NO_UNKOWN_MEM; |
0 |
8627 |
MLK = NO_UNKOWN_MEM; |
0 |
| 8628 |
} else { |
--- |
8628 |
} else { |
--- |
| 8629 |
MLK = NO_UNKOWN_MEM; |
0 |
8629 |
MLK = NO_UNKOWN_MEM; |
0 |
| 8630 |
} |
--- |
8630 |
} |
--- |
| 8631 |
|
--- |
8631 |
|
--- |
| 8632 |
assert(MLK != NO_LOCATIONS && "No location specified!"); |
0 |
8632 |
assert(MLK != NO_LOCATIONS && "No location specified!"); |
0 |
| 8633 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Ptr value can be categorized: " |
0 |
8633 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Ptr value can be categorized: " |
0 |
| 8634 |
<< Obj << " -> " << getMemoryLocationsAsStr(MLK) << "\n"); |
--- |
8634 |
<< Obj << " -> " << getMemoryLocationsAsStr(MLK) << "\n"); |
--- |
| 8635 |
updateStateAndAccessesMap(State, MLK, &I, &Obj, Changed, |
0 |
8635 |
updateStateAndAccessesMap(State, MLK, &I, &Obj, Changed, |
0 |
| 8636 |
getAccessKindFromInst(&I)); |
--- |
8636 |
getAccessKindFromInst(&I)); |
--- |
| 8637 |
|
--- |
8637 |
|
--- |
| 8638 |
return true; |
0 |
8638 |
return true; |
0 |
| 8639 |
}; |
0 |
8639 |
}; |
0 |
| 8640 |
|
--- |
8640 |
|
--- |
| 8641 |
const auto *AA = A.getAAFor( |
0 |
8641 |
const auto *AA = A.getAAFor( |
0 |
| 8642 |
*this, IRPosition::value(Ptr), DepClassTy::OPTIONAL); |
0 |
8642 |
*this, IRPosition::value(Ptr), DepClassTy::OPTIONAL); |
0 |
| 8643 |
if (!AA || !AA->forallUnderlyingObjects(Pred, AA::Intraprocedural)) { |
0 |
8643 |
if (!AA || !AA->forallUnderlyingObjects(Pred, AA::Intraprocedural)) { |
0 |
| 8644 |
LLVM_DEBUG( |
0 |
8644 |
LLVM_DEBUG( |
0 |
| 8645 |
dbgs() << "[AAMemoryLocation] Pointer locations not categorized\n"); |
--- |
8645 |
dbgs() << "[AAMemoryLocation] Pointer locations not categorized\n"); |
--- |
| 8646 |
updateStateAndAccessesMap(State, NO_UNKOWN_MEM, &I, nullptr, Changed, |
0 |
8646 |
updateStateAndAccessesMap(State, NO_UNKOWN_MEM, &I, nullptr, Changed, |
0 |
| 8647 |
getAccessKindFromInst(&I)); |
--- |
8647 |
getAccessKindFromInst(&I)); |
--- |
| 8648 |
return; |
0 |
8648 |
return; |
0 |
| 8649 |
} |
--- |
8649 |
} |
--- |
| 8650 |
|
--- |
8650 |
|
--- |
| 8651 |
LLVM_DEBUG( |
0 |
8651 |
LLVM_DEBUG( |
0 |
| 8652 |
dbgs() << "[AAMemoryLocation] Accessed locations with pointer locations: " |
--- |
8652 |
dbgs() << "[AAMemoryLocation] Accessed locations with pointer locations: " |
--- |
| 8653 |
<< getMemoryLocationsAsStr(State.getAssumed()) << "\n"); |
--- |
8653 |
<< getMemoryLocationsAsStr(State.getAssumed()) << "\n"); |
--- |
| 8654 |
} |
--- |
8654 |
} |
--- |
| 8655 |
|
--- |
8655 |
|
--- |
| 8656 |
void AAMemoryLocationImpl::categorizeArgumentPointerLocations( |
0 |
8656 |
void AAMemoryLocationImpl::categorizeArgumentPointerLocations( |
0 |
| 8657 |
Attributor &A, CallBase &CB, AAMemoryLocation::StateType &AccessedLocs, |
--- |
8657 |
Attributor &A, CallBase &CB, AAMemoryLocation::StateType &AccessedLocs, |
--- |
| 8658 |
bool &Changed) { |
--- |
8658 |
bool &Changed) { |
--- |
| 8659 |
for (unsigned ArgNo = 0, E = CB.arg_size(); ArgNo < E; ++ArgNo) { |
0 |
8659 |
for (unsigned ArgNo = 0, E = CB.arg_size(); ArgNo < E; ++ArgNo) { |
0 |
| 8660 |
|
--- |
8660 |
|
--- |
| 8661 |
// Skip non-pointer arguments. |
--- |
8661 |
// Skip non-pointer arguments. |
--- |
| 8662 |
const Value *ArgOp = CB.getArgOperand(ArgNo); |
0 |
8662 |
const Value *ArgOp = CB.getArgOperand(ArgNo); |
0 |
| 8663 |
if (!ArgOp->getType()->isPtrOrPtrVectorTy()) |
0 |
8663 |
if (!ArgOp->getType()->isPtrOrPtrVectorTy()) |
0 |
| 8664 |
continue; |
0 |
8664 |
continue; |
0 |
| 8665 |
|
--- |
8665 |
|
--- |
| 8666 |
// Skip readnone arguments. |
--- |
8666 |
// Skip readnone arguments. |
--- |
| 8667 |
const IRPosition &ArgOpIRP = IRPosition::callsite_argument(CB, ArgNo); |
0 |
8667 |
const IRPosition &ArgOpIRP = IRPosition::callsite_argument(CB, ArgNo); |
0 |
| 8668 |
const auto *ArgOpMemLocationAA = |
--- |
8668 |
const auto *ArgOpMemLocationAA = |
--- |
| 8669 |
A.getAAFor(*this, ArgOpIRP, DepClassTy::OPTIONAL); |
0 |
8669 |
A.getAAFor(*this, ArgOpIRP, DepClassTy::OPTIONAL); |
0 |
| 8670 |
|
--- |
8670 |
|
--- |
| 8671 |
if (ArgOpMemLocationAA && ArgOpMemLocationAA->isAssumedReadNone()) |
0 |
8671 |
if (ArgOpMemLocationAA && ArgOpMemLocationAA->isAssumedReadNone()) |
0 |
| 8672 |
continue; |
0 |
8672 |
continue; |
0 |
| 8673 |
|
--- |
8673 |
|
--- |
| 8674 |
// Categorize potentially accessed pointer arguments as if there was an |
--- |
8674 |
// Categorize potentially accessed pointer arguments as if there was an |
--- |
| 8675 |
// access instruction with them as pointer. |
--- |
8675 |
// access instruction with them as pointer. |
--- |
| 8676 |
categorizePtrValue(A, CB, *ArgOp, AccessedLocs, Changed); |
0 |
8676 |
categorizePtrValue(A, CB, *ArgOp, AccessedLocs, Changed); |
0 |
| 8677 |
} |
--- |
8677 |
} |
--- |
| 8678 |
} |
0 |
8678 |
} |
0 |
| 8679 |
|
--- |
8679 |
|
--- |
| 8680 |
AAMemoryLocation::MemoryLocationsKind |
--- |
8680 |
AAMemoryLocation::MemoryLocationsKind |
--- |
| 8681 |
AAMemoryLocationImpl::categorizeAccessedLocations(Attributor &A, Instruction &I, |
0 |
8681 |
AAMemoryLocationImpl::categorizeAccessedLocations(Attributor &A, Instruction &I, |
0 |
| 8682 |
bool &Changed) { |
--- |
8682 |
bool &Changed) { |
--- |
| 8683 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Categorize accessed locations for " |
0 |
8683 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Categorize accessed locations for " |
0 |
| 8684 |
<< I << "\n"); |
--- |
8684 |
<< I << "\n"); |
--- |
| 8685 |
|
--- |
8685 |
|
--- |
| 8686 |
AAMemoryLocation::StateType AccessedLocs; |
0 |
8686 |
AAMemoryLocation::StateType AccessedLocs; |
0 |
| 8687 |
AccessedLocs.intersectAssumedBits(NO_LOCATIONS); |
0 |
8687 |
AccessedLocs.intersectAssumedBits(NO_LOCATIONS); |
0 |
| 8688 |
|
--- |
8688 |
|
--- |
| 8689 |
if (auto *CB = dyn_cast(&I)) { |
0 |
8689 |
if (auto *CB = dyn_cast(&I)) { |
0 |
| 8690 |
|
--- |
8690 |
|
--- |
| 8691 |
// First check if we assume any memory is access is visible. |
--- |
8691 |
// First check if we assume any memory is access is visible. |
--- |
| 8692 |
const auto *CBMemLocationAA = A.getAAFor( |
0 |
8692 |
const auto *CBMemLocationAA = A.getAAFor( |
0 |
| 8693 |
*this, IRPosition::callsite_function(*CB), DepClassTy::OPTIONAL); |
0 |
8693 |
*this, IRPosition::callsite_function(*CB), DepClassTy::OPTIONAL); |
0 |
| 8694 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Categorize call site: " << I |
0 |
8694 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Categorize call site: " << I |
0 |
| 8695 |
<< " [" << CBMemLocationAA << "]\n"); |
--- |
8695 |
<< " [" << CBMemLocationAA << "]\n"); |
--- |
| 8696 |
if (!CBMemLocationAA) { |
0 |
8696 |
if (!CBMemLocationAA) { |
0 |
| 8697 |
updateStateAndAccessesMap(AccessedLocs, NO_UNKOWN_MEM, &I, nullptr, |
0 |
8697 |
updateStateAndAccessesMap(AccessedLocs, NO_UNKOWN_MEM, &I, nullptr, |
0 |
| 8698 |
Changed, getAccessKindFromInst(&I)); |
--- |
8698 |
Changed, getAccessKindFromInst(&I)); |
--- |
| 8699 |
return NO_UNKOWN_MEM; |
0 |
8699 |
return NO_UNKOWN_MEM; |
0 |
| 8700 |
} |
--- |
8700 |
} |
--- |
| 8701 |
|
--- |
8701 |
|
--- |
| 8702 |
if (CBMemLocationAA->isAssumedReadNone()) |
0 |
8702 |
if (CBMemLocationAA->isAssumedReadNone()) |
0 |
| 8703 |
return NO_LOCATIONS; |
0 |
8703 |
return NO_LOCATIONS; |
0 |
| 8704 |
|
--- |
8704 |
|
--- |
| 8705 |
if (CBMemLocationAA->isAssumedInaccessibleMemOnly()) { |
0 |
8705 |
if (CBMemLocationAA->isAssumedInaccessibleMemOnly()) { |
0 |
| 8706 |
updateStateAndAccessesMap(AccessedLocs, NO_INACCESSIBLE_MEM, &I, nullptr, |
0 |
8706 |
updateStateAndAccessesMap(AccessedLocs, NO_INACCESSIBLE_MEM, &I, nullptr, |
0 |
| 8707 |
Changed, getAccessKindFromInst(&I)); |
--- |
8707 |
Changed, getAccessKindFromInst(&I)); |
--- |
| 8708 |
return AccessedLocs.getAssumed(); |
0 |
8708 |
return AccessedLocs.getAssumed(); |
0 |
| 8709 |
} |
--- |
8709 |
} |
--- |
| 8710 |
|
--- |
8710 |
|
--- |
| 8711 |
uint32_t CBAssumedNotAccessedLocs = |
--- |
8711 |
uint32_t CBAssumedNotAccessedLocs = |
--- |
| 8712 |
CBMemLocationAA->getAssumedNotAccessedLocation(); |
0 |
8712 |
CBMemLocationAA->getAssumedNotAccessedLocation(); |
0 |
| 8713 |
|
--- |
8713 |
|
--- |
| 8714 |
// Set the argmemonly and global bit as we handle them separately below. |
--- |
8714 |
// Set the argmemonly and global bit as we handle them separately below. |
--- |
| 8715 |
uint32_t CBAssumedNotAccessedLocsNoArgMem = |
0 |
8715 |
uint32_t CBAssumedNotAccessedLocsNoArgMem = |
0 |
| 8716 |
CBAssumedNotAccessedLocs | NO_ARGUMENT_MEM | NO_GLOBAL_MEM; |
--- |
8716 |
CBAssumedNotAccessedLocs | NO_ARGUMENT_MEM | NO_GLOBAL_MEM; |
--- |
| 8717 |
|
--- |
8717 |
|
--- |
| 8718 |
for (MemoryLocationsKind CurMLK = 1; CurMLK < NO_LOCATIONS; CurMLK *= 2) { |
0 |
8718 |
for (MemoryLocationsKind CurMLK = 1; CurMLK < NO_LOCATIONS; CurMLK *= 2) { |
0 |
| 8719 |
if (CBAssumedNotAccessedLocsNoArgMem & CurMLK) |
0 |
8719 |
if (CBAssumedNotAccessedLocsNoArgMem & CurMLK) |
0 |
| 8720 |
continue; |
0 |
8720 |
continue; |
0 |
| 8721 |
updateStateAndAccessesMap(AccessedLocs, CurMLK, &I, nullptr, Changed, |
0 |
8721 |
updateStateAndAccessesMap(AccessedLocs, CurMLK, &I, nullptr, Changed, |
0 |
| 8722 |
getAccessKindFromInst(&I)); |
--- |
8722 |
getAccessKindFromInst(&I)); |
--- |
| 8723 |
} |
--- |
8723 |
} |
--- |
| 8724 |
|
--- |
8724 |
|
--- |
| 8725 |
// Now handle global memory if it might be accessed. This is slightly tricky |
--- |
8725 |
// Now handle global memory if it might be accessed. This is slightly tricky |
--- |
| 8726 |
// as NO_GLOBAL_MEM has multiple bits set. |
--- |
8726 |
// as NO_GLOBAL_MEM has multiple bits set. |
--- |
| 8727 |
bool HasGlobalAccesses = ((~CBAssumedNotAccessedLocs) & NO_GLOBAL_MEM); |
0 |
8727 |
bool HasGlobalAccesses = ((~CBAssumedNotAccessedLocs) & NO_GLOBAL_MEM); |
0 |
| 8728 |
if (HasGlobalAccesses) { |
0 |
8728 |
if (HasGlobalAccesses) { |
0 |
| 8729 |
auto AccessPred = [&](const Instruction *, const Value *Ptr, |
0 |
8729 |
auto AccessPred = [&](const Instruction *, const Value *Ptr, |
0 |
| 8730 |
AccessKind Kind, MemoryLocationsKind MLK) { |
--- |
8730 |
AccessKind Kind, MemoryLocationsKind MLK) { |
--- |
| 8731 |
updateStateAndAccessesMap(AccessedLocs, MLK, &I, Ptr, Changed, |
0 |
8731 |
updateStateAndAccessesMap(AccessedLocs, MLK, &I, Ptr, Changed, |
0 |
| 8732 |
getAccessKindFromInst(&I)); |
0 |
8732 |
getAccessKindFromInst(&I)); |
0 |
| 8733 |
return true; |
0 |
8733 |
return true; |
0 |
| 8734 |
}; |
0 |
8734 |
}; |
0 |
| 8735 |
if (!CBMemLocationAA->checkForAllAccessesToMemoryKind( |
0 |
8735 |
if (!CBMemLocationAA->checkForAllAccessesToMemoryKind( |
0 |
| 8736 |
AccessPred, inverseLocation(NO_GLOBAL_MEM, false, false))) |
--- |
8736 |
AccessPred, inverseLocation(NO_GLOBAL_MEM, false, false))) |
--- |
| 8737 |
return AccessedLocs.getWorstState(); |
0 |
8737 |
return AccessedLocs.getWorstState(); |
0 |
| 8738 |
} |
--- |
8738 |
} |
--- |
| 8739 |
|
--- |
8739 |
|
--- |
| 8740 |
LLVM_DEBUG( |
0 |
8740 |
LLVM_DEBUG( |
0 |
| 8741 |
dbgs() << "[AAMemoryLocation] Accessed state before argument handling: " |
--- |
8741 |
dbgs() << "[AAMemoryLocation] Accessed state before argument handling: " |
--- |
| 8742 |
<< getMemoryLocationsAsStr(AccessedLocs.getAssumed()) << "\n"); |
--- |
8742 |
<< getMemoryLocationsAsStr(AccessedLocs.getAssumed()) << "\n"); |
--- |
| 8743 |
|
--- |
8743 |
|
--- |
| 8744 |
// Now handle argument memory if it might be accessed. |
--- |
8744 |
// Now handle argument memory if it might be accessed. |
--- |
| 8745 |
bool HasArgAccesses = ((~CBAssumedNotAccessedLocs) & NO_ARGUMENT_MEM); |
0 |
8745 |
bool HasArgAccesses = ((~CBAssumedNotAccessedLocs) & NO_ARGUMENT_MEM); |
0 |
| 8746 |
if (HasArgAccesses) |
0 |
8746 |
if (HasArgAccesses) |
0 |
| 8747 |
categorizeArgumentPointerLocations(A, *CB, AccessedLocs, Changed); |
0 |
8747 |
categorizeArgumentPointerLocations(A, *CB, AccessedLocs, Changed); |
0 |
| 8748 |
|
--- |
8748 |
|
--- |
| 8749 |
LLVM_DEBUG( |
0 |
8749 |
LLVM_DEBUG( |
0 |
| 8750 |
dbgs() << "[AAMemoryLocation] Accessed state after argument handling: " |
--- |
8750 |
dbgs() << "[AAMemoryLocation] Accessed state after argument handling: " |
--- |
| 8751 |
<< getMemoryLocationsAsStr(AccessedLocs.getAssumed()) << "\n"); |
--- |
8751 |
<< getMemoryLocationsAsStr(AccessedLocs.getAssumed()) << "\n"); |
--- |
| 8752 |
|
--- |
8752 |
|
--- |
| 8753 |
return AccessedLocs.getAssumed(); |
0 |
8753 |
return AccessedLocs.getAssumed(); |
0 |
| 8754 |
} |
--- |
8754 |
} |
--- |
| 8755 |
|
--- |
8755 |
|
--- |
| 8756 |
if (const Value *Ptr = getPointerOperand(&I, /* AllowVolatile */ true)) { |
0 |
8756 |
if (const Value *Ptr = getPointerOperand(&I, /* AllowVolatile */ true)) { |
0 |
| 8757 |
LLVM_DEBUG( |
0 |
8757 |
LLVM_DEBUG( |
0 |
| 8758 |
dbgs() << "[AAMemoryLocation] Categorize memory access with pointer: " |
--- |
8758 |
dbgs() << "[AAMemoryLocation] Categorize memory access with pointer: " |
--- |
| 8759 |
<< I << " [" << *Ptr << "]\n"); |
--- |
8759 |
<< I << " [" << *Ptr << "]\n"); |
--- |
| 8760 |
categorizePtrValue(A, I, *Ptr, AccessedLocs, Changed, |
0 |
8760 |
categorizePtrValue(A, I, *Ptr, AccessedLocs, Changed, |
0 |
| 8761 |
Ptr->getType()->getPointerAddressSpace()); |
--- |
8761 |
Ptr->getType()->getPointerAddressSpace()); |
--- |
| 8762 |
return AccessedLocs.getAssumed(); |
0 |
8762 |
return AccessedLocs.getAssumed(); |
0 |
| 8763 |
} |
--- |
8763 |
} |
--- |
| 8764 |
|
--- |
8764 |
|
--- |
| 8765 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Failed to categorize instruction: " |
0 |
8765 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Failed to categorize instruction: " |
0 |
| 8766 |
<< I << "\n"); |
--- |
8766 |
<< I << "\n"); |
--- |
| 8767 |
updateStateAndAccessesMap(AccessedLocs, NO_UNKOWN_MEM, &I, nullptr, Changed, |
0 |
8767 |
updateStateAndAccessesMap(AccessedLocs, NO_UNKOWN_MEM, &I, nullptr, Changed, |
0 |
| 8768 |
getAccessKindFromInst(&I)); |
--- |
8768 |
getAccessKindFromInst(&I)); |
--- |
| 8769 |
return AccessedLocs.getAssumed(); |
0 |
8769 |
return AccessedLocs.getAssumed(); |
0 |
| 8770 |
} |
0 |
8770 |
} |
0 |
| 8771 |
|
--- |
8771 |
|
--- |
| 8772 |
/// An AA to represent the memory behavior function attributes. |
--- |
8772 |
/// An AA to represent the memory behavior function attributes. |
--- |
| 8773 |
struct AAMemoryLocationFunction final : public AAMemoryLocationImpl { |
--- |
8773 |
struct AAMemoryLocationFunction final : public AAMemoryLocationImpl { |
--- |
| 8774 |
AAMemoryLocationFunction(const IRPosition &IRP, Attributor &A) |
0 |
8774 |
AAMemoryLocationFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 8775 |
: AAMemoryLocationImpl(IRP, A) {} |
0 |
8775 |
: AAMemoryLocationImpl(IRP, A) {} |
0 |
| 8776 |
|
--- |
8776 |
|
--- |
| 8777 |
/// See AbstractAttribute::updateImpl(Attributor &A). |
--- |
8777 |
/// See AbstractAttribute::updateImpl(Attributor &A). |
--- |
| 8778 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
8778 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 8779 |
|
--- |
8779 |
|
--- |
| 8780 |
const auto *MemBehaviorAA = |
--- |
8780 |
const auto *MemBehaviorAA = |
--- |
| 8781 |
A.getAAFor(*this, getIRPosition(), DepClassTy::NONE); |
0 |
8781 |
A.getAAFor(*this, getIRPosition(), DepClassTy::NONE); |
0 |
| 8782 |
if (MemBehaviorAA && MemBehaviorAA->isAssumedReadNone()) { |
0 |
8782 |
if (MemBehaviorAA && MemBehaviorAA->isAssumedReadNone()) { |
0 |
| 8783 |
if (MemBehaviorAA->isKnownReadNone()) |
0 |
8783 |
if (MemBehaviorAA->isKnownReadNone()) |
0 |
| 8784 |
return indicateOptimisticFixpoint(); |
0 |
8784 |
return indicateOptimisticFixpoint(); |
0 |
| 8785 |
assert(isAssumedReadNone() && |
0 |
8785 |
assert(isAssumedReadNone() && |
0 |
| 8786 |
"AAMemoryLocation was not read-none but AAMemoryBehavior was!"); |
--- |
8786 |
"AAMemoryLocation was not read-none but AAMemoryBehavior was!"); |
--- |
| 8787 |
A.recordDependence(*MemBehaviorAA, *this, DepClassTy::OPTIONAL); |
0 |
8787 |
A.recordDependence(*MemBehaviorAA, *this, DepClassTy::OPTIONAL); |
0 |
| 8788 |
return ChangeStatus::UNCHANGED; |
0 |
8788 |
return ChangeStatus::UNCHANGED; |
0 |
| 8789 |
} |
--- |
8789 |
} |
--- |
| 8790 |
|
--- |
8790 |
|
--- |
| 8791 |
// The current assumed state used to determine a change. |
--- |
8791 |
// The current assumed state used to determine a change. |
--- |
| 8792 |
auto AssumedState = getAssumed(); |
0 |
8792 |
auto AssumedState = getAssumed(); |
0 |
| 8793 |
bool Changed = false; |
0 |
8793 |
bool Changed = false; |
0 |
| 8794 |
|
--- |
8794 |
|
--- |
| 8795 |
auto CheckRWInst = [&](Instruction &I) { |
0 |
8795 |
auto CheckRWInst = [&](Instruction &I) { |
0 |
| 8796 |
MemoryLocationsKind MLK = categorizeAccessedLocations(A, I, Changed); |
0 |
8796 |
MemoryLocationsKind MLK = categorizeAccessedLocations(A, I, Changed); |
0 |
| 8797 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Accessed locations for " << I |
0 |
8797 |
LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Accessed locations for " << I |
0 |
| 8798 |
<< ": " << getMemoryLocationsAsStr(MLK) << "\n"); |
--- |
8798 |
<< ": " << getMemoryLocationsAsStr(MLK) << "\n"); |
--- |
| 8799 |
removeAssumedBits(inverseLocation(MLK, false, false)); |
0 |
8799 |
removeAssumedBits(inverseLocation(MLK, false, false)); |
0 |
| 8800 |
// Stop once only the valid bit set in the *not assumed location*, thus |
--- |
8800 |
// Stop once only the valid bit set in the *not assumed location*, thus |
--- |
| 8801 |
// once we don't actually exclude any memory locations in the state. |
--- |
8801 |
// once we don't actually exclude any memory locations in the state. |
--- |
| 8802 |
return getAssumedNotAccessedLocation() != VALID_STATE; |
0 |
8802 |
return getAssumedNotAccessedLocation() != VALID_STATE; |
0 |
| 8803 |
}; |
0 |
8803 |
}; |
0 |
| 8804 |
|
--- |
8804 |
|
--- |
| 8805 |
bool UsedAssumedInformation = false; |
0 |
8805 |
bool UsedAssumedInformation = false; |
0 |
| 8806 |
if (!A.checkForAllReadWriteInstructions(CheckRWInst, *this, |
0 |
8806 |
if (!A.checkForAllReadWriteInstructions(CheckRWInst, *this, |
0 |
| 8807 |
UsedAssumedInformation)) |
--- |
8807 |
UsedAssumedInformation)) |
--- |
| 8808 |
return indicatePessimisticFixpoint(); |
0 |
8808 |
return indicatePessimisticFixpoint(); |
0 |
| 8809 |
|
--- |
8809 |
|
--- |
| 8810 |
Changed |= AssumedState != getAssumed(); |
0 |
8810 |
Changed |= AssumedState != getAssumed(); |
0 |
| 8811 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
8811 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
| 8812 |
} |
--- |
8812 |
} |
--- |
| 8813 |
|
--- |
8813 |
|
--- |
| 8814 |
/// See AbstractAttribute::trackStatistics() |
--- |
8814 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 8815 |
void trackStatistics() const override { |
0 |
8815 |
void trackStatistics() const override { |
0 |
| 8816 |
if (isAssumedReadNone()) |
0 |
8816 |
if (isAssumedReadNone()) |
0 |
| 8817 |
STATS_DECLTRACK_FN_ATTR(readnone) |
0 |
8817 |
STATS_DECLTRACK_FN_ATTR(readnone) |
0 |
| 8818 |
else if (isAssumedArgMemOnly()) |
0 |
8818 |
else if (isAssumedArgMemOnly()) |
0 |
| 8819 |
STATS_DECLTRACK_FN_ATTR(argmemonly) |
0 |
8819 |
STATS_DECLTRACK_FN_ATTR(argmemonly) |
0 |
| 8820 |
else if (isAssumedInaccessibleMemOnly()) |
0 |
8820 |
else if (isAssumedInaccessibleMemOnly()) |
0 |
| 8821 |
STATS_DECLTRACK_FN_ATTR(inaccessiblememonly) |
0 |
8821 |
STATS_DECLTRACK_FN_ATTR(inaccessiblememonly) |
0 |
| 8822 |
else if (isAssumedInaccessibleOrArgMemOnly()) |
0 |
8822 |
else if (isAssumedInaccessibleOrArgMemOnly()) |
0 |
| 8823 |
STATS_DECLTRACK_FN_ATTR(inaccessiblememorargmemonly) |
0 |
8823 |
STATS_DECLTRACK_FN_ATTR(inaccessiblememorargmemonly) |
0 |
| 8824 |
} |
0 |
8824 |
} |
0 |
| 8825 |
}; |
--- |
8825 |
}; |
--- |
| 8826 |
|
--- |
8826 |
|
--- |
| 8827 |
/// AAMemoryLocation attribute for call sites. |
--- |
8827 |
/// AAMemoryLocation attribute for call sites. |
--- |
| 8828 |
struct AAMemoryLocationCallSite final : AAMemoryLocationImpl { |
--- |
8828 |
struct AAMemoryLocationCallSite final : AAMemoryLocationImpl { |
--- |
| 8829 |
AAMemoryLocationCallSite(const IRPosition &IRP, Attributor &A) |
0 |
8829 |
AAMemoryLocationCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 8830 |
: AAMemoryLocationImpl(IRP, A) {} |
0 |
8830 |
: AAMemoryLocationImpl(IRP, A) {} |
0 |
| 8831 |
|
--- |
8831 |
|
--- |
| 8832 |
/// See AbstractAttribute::updateImpl(...). |
--- |
8832 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 8833 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
8833 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 8834 |
// TODO: Once we have call site specific value information we can provide |
--- |
8834 |
// TODO: Once we have call site specific value information we can provide |
--- |
| 8835 |
// call site specific liveness liveness information and then it makes |
--- |
8835 |
// call site specific liveness liveness information and then it makes |
--- |
| 8836 |
// sense to specialize attributes for call sites arguments instead of |
--- |
8836 |
// sense to specialize attributes for call sites arguments instead of |
--- |
| 8837 |
// redirecting requests to the callee argument. |
--- |
8837 |
// redirecting requests to the callee argument. |
--- |
| 8838 |
Function *F = getAssociatedFunction(); |
0 |
8838 |
Function *F = getAssociatedFunction(); |
0 |
| 8839 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
8839 |
const IRPosition &FnPos = IRPosition::function(*F); |
0 |
| 8840 |
auto *FnAA = |
--- |
8840 |
auto *FnAA = |
--- |
| 8841 |
A.getAAFor(*this, FnPos, DepClassTy::REQUIRED); |
0 |
8841 |
A.getAAFor(*this, FnPos, DepClassTy::REQUIRED); |
0 |
| 8842 |
if (!FnAA) |
0 |
8842 |
if (!FnAA) |
0 |
| 8843 |
return indicatePessimisticFixpoint(); |
0 |
8843 |
return indicatePessimisticFixpoint(); |
0 |
| 8844 |
bool Changed = false; |
0 |
8844 |
bool Changed = false; |
0 |
| 8845 |
auto AccessPred = [&](const Instruction *I, const Value *Ptr, |
0 |
8845 |
auto AccessPred = [&](const Instruction *I, const Value *Ptr, |
0 |
| 8846 |
AccessKind Kind, MemoryLocationsKind MLK) { |
--- |
8846 |
AccessKind Kind, MemoryLocationsKind MLK) { |
--- |
| 8847 |
updateStateAndAccessesMap(getState(), MLK, I, Ptr, Changed, |
0 |
8847 |
updateStateAndAccessesMap(getState(), MLK, I, Ptr, Changed, |
0 |
| 8848 |
getAccessKindFromInst(I)); |
--- |
8848 |
getAccessKindFromInst(I)); |
--- |
| 8849 |
return true; |
0 |
8849 |
return true; |
0 |
| 8850 |
}; |
0 |
8850 |
}; |
0 |
| 8851 |
if (!FnAA->checkForAllAccessesToMemoryKind(AccessPred, ALL_LOCATIONS)) |
0 |
8851 |
if (!FnAA->checkForAllAccessesToMemoryKind(AccessPred, ALL_LOCATIONS)) |
0 |
| 8852 |
return indicatePessimisticFixpoint(); |
0 |
8852 |
return indicatePessimisticFixpoint(); |
0 |
| 8853 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
8853 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
| 8854 |
} |
--- |
8854 |
} |
--- |
| 8855 |
|
--- |
8855 |
|
--- |
| 8856 |
/// See AbstractAttribute::trackStatistics() |
--- |
8856 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 8857 |
void trackStatistics() const override { |
0 |
8857 |
void trackStatistics() const override { |
0 |
| 8858 |
if (isAssumedReadNone()) |
0 |
8858 |
if (isAssumedReadNone()) |
0 |
| 8859 |
STATS_DECLTRACK_CS_ATTR(readnone) |
0 |
8859 |
STATS_DECLTRACK_CS_ATTR(readnone) |
0 |
| 8860 |
} |
0 |
8860 |
} |
0 |
| 8861 |
}; |
--- |
8861 |
}; |
--- |
| 8862 |
} // namespace |
--- |
8862 |
} // namespace |
--- |
| 8863 |
|
--- |
8863 |
|
--- |
| 8864 |
/// ------------------ Value Constant Range Attribute ------------------------- |
--- |
8864 |
/// ------------------ Value Constant Range Attribute ------------------------- |
--- |
| 8865 |
|
--- |
8865 |
|
--- |
| 8866 |
namespace { |
--- |
8866 |
namespace { |
--- |
| 8867 |
struct AAValueConstantRangeImpl : AAValueConstantRange { |
--- |
8867 |
struct AAValueConstantRangeImpl : AAValueConstantRange { |
--- |
| 8868 |
using StateType = IntegerRangeState; |
--- |
8868 |
using StateType = IntegerRangeState; |
--- |
| 8869 |
AAValueConstantRangeImpl(const IRPosition &IRP, Attributor &A) |
0 |
8869 |
AAValueConstantRangeImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 8870 |
: AAValueConstantRange(IRP, A) {} |
0 |
8870 |
: AAValueConstantRange(IRP, A) {} |
0 |
| 8871 |
|
--- |
8871 |
|
--- |
| 8872 |
/// See AbstractAttribute::initialize(..). |
--- |
8872 |
/// See AbstractAttribute::initialize(..). |
--- |
| 8873 |
void initialize(Attributor &A) override { |
0 |
8873 |
void initialize(Attributor &A) override { |
0 |
| 8874 |
if (A.hasSimplificationCallback(getIRPosition())) { |
0 |
8874 |
if (A.hasSimplificationCallback(getIRPosition())) { |
0 |
| 8875 |
indicatePessimisticFixpoint(); |
0 |
8875 |
indicatePessimisticFixpoint(); |
0 |
| 8876 |
return; |
0 |
8876 |
return; |
0 |
| 8877 |
} |
--- |
8877 |
} |
--- |
| 8878 |
|
--- |
8878 |
|
--- |
| 8879 |
// Intersect a range given by SCEV. |
--- |
8879 |
// Intersect a range given by SCEV. |
--- |
| 8880 |
intersectKnown(getConstantRangeFromSCEV(A, getCtxI())); |
0 |
8880 |
intersectKnown(getConstantRangeFromSCEV(A, getCtxI())); |
0 |
| 8881 |
|
--- |
8881 |
|
--- |
| 8882 |
// Intersect a range given by LVI. |
--- |
8882 |
// Intersect a range given by LVI. |
--- |
| 8883 |
intersectKnown(getConstantRangeFromLVI(A, getCtxI())); |
0 |
8883 |
intersectKnown(getConstantRangeFromLVI(A, getCtxI())); |
0 |
| 8884 |
} |
--- |
8884 |
} |
--- |
| 8885 |
|
--- |
8885 |
|
--- |
| 8886 |
/// See AbstractAttribute::getAsStr(). |
--- |
8886 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 8887 |
const std::string getAsStr(Attributor *A) const override { |
0 |
8887 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 8888 |
std::string Str; |
0 |
8888 |
std::string Str; |
0 |
| 8889 |
llvm::raw_string_ostream OS(Str); |
0 |
8889 |
llvm::raw_string_ostream OS(Str); |
0 |
| 8890 |
OS << "range(" << getBitWidth() << ")<"; |
0 |
8890 |
OS << "range(" << getBitWidth() << ")<"; |
0 |
| 8891 |
getKnown().print(OS); |
0 |
8891 |
getKnown().print(OS); |
0 |
| 8892 |
OS << " / "; |
0 |
8892 |
OS << " / "; |
0 |
| 8893 |
getAssumed().print(OS); |
0 |
8893 |
getAssumed().print(OS); |
0 |
| 8894 |
OS << ">"; |
0 |
8894 |
OS << ">"; |
0 |
| 8895 |
return OS.str(); |
0 |
8895 |
return OS.str(); |
0 |
| 8896 |
} |
0 |
8896 |
} |
0 |
| 8897 |
|
--- |
8897 |
|
--- |
| 8898 |
/// Helper function to get a SCEV expr for the associated value at program |
--- |
8898 |
/// Helper function to get a SCEV expr for the associated value at program |
--- |
| 8899 |
/// point \p I. |
--- |
8899 |
/// point \p I. |
--- |
| 8900 |
const SCEV *getSCEV(Attributor &A, const Instruction *I = nullptr) const { |
0 |
8900 |
const SCEV *getSCEV(Attributor &A, const Instruction *I = nullptr) const { |
0 |
| 8901 |
if (!getAnchorScope()) |
0 |
8901 |
if (!getAnchorScope()) |
0 |
| 8902 |
return nullptr; |
0 |
8902 |
return nullptr; |
0 |
| 8903 |
|
--- |
8903 |
|
--- |
| 8904 |
ScalarEvolution *SE = |
--- |
8904 |
ScalarEvolution *SE = |
--- |
| 8905 |
A.getInfoCache().getAnalysisResultForFunction( |
0 |
8905 |
A.getInfoCache().getAnalysisResultForFunction( |
0 |
| 8906 |
*getAnchorScope()); |
0 |
8906 |
*getAnchorScope()); |
0 |
| 8907 |
|
--- |
8907 |
|
--- |
| 8908 |
LoopInfo *LI = A.getInfoCache().getAnalysisResultForFunction( |
0 |
8908 |
LoopInfo *LI = A.getInfoCache().getAnalysisResultForFunction( |
0 |
| 8909 |
*getAnchorScope()); |
0 |
8909 |
*getAnchorScope()); |
0 |
| 8910 |
|
--- |
8910 |
|
--- |
| 8911 |
if (!SE || !LI) |
0 |
8911 |
if (!SE || !LI) |
0 |
| 8912 |
return nullptr; |
0 |
8912 |
return nullptr; |
0 |
| 8913 |
|
--- |
8913 |
|
--- |
| 8914 |
const SCEV *S = SE->getSCEV(&getAssociatedValue()); |
0 |
8914 |
const SCEV *S = SE->getSCEV(&getAssociatedValue()); |
0 |
| 8915 |
if (!I) |
0 |
8915 |
if (!I) |
0 |
| 8916 |
return S; |
0 |
8916 |
return S; |
0 |
| 8917 |
|
--- |
8917 |
|
--- |
| 8918 |
return SE->getSCEVAtScope(S, LI->getLoopFor(I->getParent())); |
0 |
8918 |
return SE->getSCEVAtScope(S, LI->getLoopFor(I->getParent())); |
0 |
| 8919 |
} |
--- |
8919 |
} |
--- |
| 8920 |
|
--- |
8920 |
|
--- |
| 8921 |
/// Helper function to get a range from SCEV for the associated value at |
--- |
8921 |
/// Helper function to get a range from SCEV for the associated value at |
--- |
| 8922 |
/// program point \p I. |
--- |
8922 |
/// program point \p I. |
--- |
| 8923 |
ConstantRange getConstantRangeFromSCEV(Attributor &A, |
0 |
8923 |
ConstantRange getConstantRangeFromSCEV(Attributor &A, |
0 |
| 8924 |
const Instruction *I = nullptr) const { |
--- |
8924 |
const Instruction *I = nullptr) const { |
--- |
| 8925 |
if (!getAnchorScope()) |
0 |
8925 |
if (!getAnchorScope()) |
0 |
| 8926 |
return getWorstState(getBitWidth()); |
0 |
8926 |
return getWorstState(getBitWidth()); |
0 |
| 8927 |
|
--- |
8927 |
|
--- |
| 8928 |
ScalarEvolution *SE = |
--- |
8928 |
ScalarEvolution *SE = |
--- |
| 8929 |
A.getInfoCache().getAnalysisResultForFunction( |
0 |
8929 |
A.getInfoCache().getAnalysisResultForFunction( |
0 |
| 8930 |
*getAnchorScope()); |
0 |
8930 |
*getAnchorScope()); |
0 |
| 8931 |
|
--- |
8931 |
|
--- |
| 8932 |
const SCEV *S = getSCEV(A, I); |
0 |
8932 |
const SCEV *S = getSCEV(A, I); |
0 |
| 8933 |
if (!SE || !S) |
0 |
8933 |
if (!SE || !S) |
0 |
| 8934 |
return getWorstState(getBitWidth()); |
0 |
8934 |
return getWorstState(getBitWidth()); |
0 |
| 8935 |
|
--- |
8935 |
|
--- |
| 8936 |
return SE->getUnsignedRange(S); |
0 |
8936 |
return SE->getUnsignedRange(S); |
0 |
| 8937 |
} |
--- |
8937 |
} |
--- |
| 8938 |
|
--- |
8938 |
|
--- |
| 8939 |
/// Helper function to get a range from LVI for the associated value at |
--- |
8939 |
/// Helper function to get a range from LVI for the associated value at |
--- |
| 8940 |
/// program point \p I. |
--- |
8940 |
/// program point \p I. |
--- |
| 8941 |
ConstantRange |
--- |
8941 |
ConstantRange |
--- |
| 8942 |
getConstantRangeFromLVI(Attributor &A, |
0 |
8942 |
getConstantRangeFromLVI(Attributor &A, |
0 |
| 8943 |
const Instruction *CtxI = nullptr) const { |
--- |
8943 |
const Instruction *CtxI = nullptr) const { |
--- |
| 8944 |
if (!getAnchorScope()) |
0 |
8944 |
if (!getAnchorScope()) |
0 |
| 8945 |
return getWorstState(getBitWidth()); |
0 |
8945 |
return getWorstState(getBitWidth()); |
0 |
| 8946 |
|
--- |
8946 |
|
--- |
| 8947 |
LazyValueInfo *LVI = |
--- |
8947 |
LazyValueInfo *LVI = |
--- |
| 8948 |
A.getInfoCache().getAnalysisResultForFunction( |
0 |
8948 |
A.getInfoCache().getAnalysisResultForFunction( |
0 |
| 8949 |
*getAnchorScope()); |
0 |
8949 |
*getAnchorScope()); |
0 |
| 8950 |
|
--- |
8950 |
|
--- |
| 8951 |
if (!LVI || !CtxI) |
0 |
8951 |
if (!LVI || !CtxI) |
0 |
| 8952 |
return getWorstState(getBitWidth()); |
0 |
8952 |
return getWorstState(getBitWidth()); |
0 |
| 8953 |
return LVI->getConstantRange(&getAssociatedValue(), |
0 |
8953 |
return LVI->getConstantRange(&getAssociatedValue(), |
0 |
| 8954 |
const_cast(CtxI)); |
0 |
8954 |
const_cast(CtxI)); |
0 |
| 8955 |
} |
--- |
8955 |
} |
--- |
| 8956 |
|
--- |
8956 |
|
--- |
| 8957 |
/// Return true if \p CtxI is valid for querying outside analyses. |
--- |
8957 |
/// Return true if \p CtxI is valid for querying outside analyses. |
--- |
| 8958 |
/// This basically makes sure we do not ask intra-procedural analysis |
--- |
8958 |
/// This basically makes sure we do not ask intra-procedural analysis |
--- |
| 8959 |
/// about a context in the wrong function or a context that violates |
--- |
8959 |
/// about a context in the wrong function or a context that violates |
--- |
| 8960 |
/// dominance assumptions they might have. The \p AllowAACtxI flag indicates |
--- |
8960 |
/// dominance assumptions they might have. The \p AllowAACtxI flag indicates |
--- |
| 8961 |
/// if the original context of this AA is OK or should be considered invalid. |
--- |
8961 |
/// if the original context of this AA is OK or should be considered invalid. |
--- |
| 8962 |
bool isValidCtxInstructionForOutsideAnalysis(Attributor &A, |
0 |
8962 |
bool isValidCtxInstructionForOutsideAnalysis(Attributor &A, |
0 |
| 8963 |
const Instruction *CtxI, |
--- |
8963 |
const Instruction *CtxI, |
--- |
| 8964 |
bool AllowAACtxI) const { |
--- |
8964 |
bool AllowAACtxI) const { |
--- |
| 8965 |
if (!CtxI || (!AllowAACtxI && CtxI == getCtxI())) |
0 |
8965 |
if (!CtxI || (!AllowAACtxI && CtxI == getCtxI())) |
0 |
| 8966 |
return false; |
0 |
8966 |
return false; |
0 |
| 8967 |
|
--- |
8967 |
|
--- |
| 8968 |
// Our context might be in a different function, neither intra-procedural |
--- |
8968 |
// Our context might be in a different function, neither intra-procedural |
--- |
| 8969 |
// analysis (ScalarEvolution nor LazyValueInfo) can handle that. |
--- |
8969 |
// analysis (ScalarEvolution nor LazyValueInfo) can handle that. |
--- |
| 8970 |
if (!AA::isValidInScope(getAssociatedValue(), CtxI->getFunction())) |
0 |
8970 |
if (!AA::isValidInScope(getAssociatedValue(), CtxI->getFunction())) |
0 |
| 8971 |
return false; |
0 |
8971 |
return false; |
0 |
| 8972 |
|
--- |
8972 |
|
--- |
| 8973 |
// If the context is not dominated by the value there are paths to the |
--- |
8973 |
// If the context is not dominated by the value there are paths to the |
--- |
| 8974 |
// context that do not define the value. This cannot be handled by |
--- |
8974 |
// context that do not define the value. This cannot be handled by |
--- |
| 8975 |
// LazyValueInfo so we need to bail. |
--- |
8975 |
// LazyValueInfo so we need to bail. |
--- |
| 8976 |
if (auto *I = dyn_cast(&getAssociatedValue())) { |
0 |
8976 |
if (auto *I = dyn_cast(&getAssociatedValue())) { |
0 |
| 8977 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
8977 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
| 8978 |
const DominatorTree *DT = |
--- |
8978 |
const DominatorTree *DT = |
--- |
| 8979 |
InfoCache.getAnalysisResultForFunction( |
0 |
8979 |
InfoCache.getAnalysisResultForFunction( |
0 |
| 8980 |
*I->getFunction()); |
0 |
8980 |
*I->getFunction()); |
0 |
| 8981 |
return DT && DT->dominates(I, CtxI); |
0 |
8981 |
return DT && DT->dominates(I, CtxI); |
0 |
| 8982 |
} |
--- |
8982 |
} |
--- |
| 8983 |
|
--- |
8983 |
|
--- |
| 8984 |
return true; |
0 |
8984 |
return true; |
0 |
| 8985 |
} |
--- |
8985 |
} |
--- |
| 8986 |
|
--- |
8986 |
|
--- |
| 8987 |
/// See AAValueConstantRange::getKnownConstantRange(..). |
--- |
8987 |
/// See AAValueConstantRange::getKnownConstantRange(..). |
--- |
| 8988 |
ConstantRange |
--- |
8988 |
ConstantRange |
--- |
| 8989 |
getKnownConstantRange(Attributor &A, |
0 |
8989 |
getKnownConstantRange(Attributor &A, |
0 |
| 8990 |
const Instruction *CtxI = nullptr) const override { |
--- |
8990 |
const Instruction *CtxI = nullptr) const override { |
--- |
| 8991 |
if (!isValidCtxInstructionForOutsideAnalysis(A, CtxI, |
0 |
8991 |
if (!isValidCtxInstructionForOutsideAnalysis(A, CtxI, |
0 |
| 8992 |
/* AllowAACtxI */ false)) |
--- |
8992 |
/* AllowAACtxI */ false)) |
--- |
| 8993 |
return getKnown(); |
0 |
8993 |
return getKnown(); |
0 |
| 8994 |
|
--- |
8994 |
|
--- |
| 8995 |
ConstantRange LVIR = getConstantRangeFromLVI(A, CtxI); |
0 |
8995 |
ConstantRange LVIR = getConstantRangeFromLVI(A, CtxI); |
0 |
| 8996 |
ConstantRange SCEVR = getConstantRangeFromSCEV(A, CtxI); |
0 |
8996 |
ConstantRange SCEVR = getConstantRangeFromSCEV(A, CtxI); |
0 |
| 8997 |
return getKnown().intersectWith(SCEVR).intersectWith(LVIR); |
0 |
8997 |
return getKnown().intersectWith(SCEVR).intersectWith(LVIR); |
0 |
| 8998 |
} |
0 |
8998 |
} |
0 |
| 8999 |
|
--- |
8999 |
|
--- |
| 9000 |
/// See AAValueConstantRange::getAssumedConstantRange(..). |
--- |
9000 |
/// See AAValueConstantRange::getAssumedConstantRange(..). |
--- |
| 9001 |
ConstantRange |
--- |
9001 |
ConstantRange |
--- |
| 9002 |
getAssumedConstantRange(Attributor &A, |
0 |
9002 |
getAssumedConstantRange(Attributor &A, |
0 |
| 9003 |
const Instruction *CtxI = nullptr) const override { |
--- |
9003 |
const Instruction *CtxI = nullptr) const override { |
--- |
| 9004 |
// TODO: Make SCEV use Attributor assumption. |
--- |
9004 |
// TODO: Make SCEV use Attributor assumption. |
--- |
| 9005 |
// We may be able to bound a variable range via assumptions in |
--- |
9005 |
// We may be able to bound a variable range via assumptions in |
--- |
| 9006 |
// Attributor. ex.) If x is assumed to be in [1, 3] and y is known to |
--- |
9006 |
// Attributor. ex.) If x is assumed to be in [1, 3] and y is known to |
--- |
| 9007 |
// evolve to x^2 + x, then we can say that y is in [2, 12]. |
--- |
9007 |
// evolve to x^2 + x, then we can say that y is in [2, 12]. |
--- |
| 9008 |
if (!isValidCtxInstructionForOutsideAnalysis(A, CtxI, |
0 |
9008 |
if (!isValidCtxInstructionForOutsideAnalysis(A, CtxI, |
0 |
| 9009 |
/* AllowAACtxI */ false)) |
--- |
9009 |
/* AllowAACtxI */ false)) |
--- |
| 9010 |
return getAssumed(); |
0 |
9010 |
return getAssumed(); |
0 |
| 9011 |
|
--- |
9011 |
|
--- |
| 9012 |
ConstantRange LVIR = getConstantRangeFromLVI(A, CtxI); |
0 |
9012 |
ConstantRange LVIR = getConstantRangeFromLVI(A, CtxI); |
0 |
| 9013 |
ConstantRange SCEVR = getConstantRangeFromSCEV(A, CtxI); |
0 |
9013 |
ConstantRange SCEVR = getConstantRangeFromSCEV(A, CtxI); |
0 |
| 9014 |
return getAssumed().intersectWith(SCEVR).intersectWith(LVIR); |
0 |
9014 |
return getAssumed().intersectWith(SCEVR).intersectWith(LVIR); |
0 |
| 9015 |
} |
0 |
9015 |
} |
0 |
| 9016 |
|
--- |
9016 |
|
--- |
| 9017 |
/// Helper function to create MDNode for range metadata. |
--- |
9017 |
/// Helper function to create MDNode for range metadata. |
--- |
| 9018 |
static MDNode * |
--- |
9018 |
static MDNode * |
--- |
| 9019 |
getMDNodeForConstantRange(Type *Ty, LLVMContext &Ctx, |
0 |
9019 |
getMDNodeForConstantRange(Type *Ty, LLVMContext &Ctx, |
0 |
| 9020 |
const ConstantRange &AssumedConstantRange) { |
--- |
9020 |
const ConstantRange &AssumedConstantRange) { |
--- |
| 9021 |
Metadata *LowAndHigh[] = {ConstantAsMetadata::get(ConstantInt::get( |
0 |
9021 |
Metadata *LowAndHigh[] = {ConstantAsMetadata::get(ConstantInt::get( |
0 |
| 9022 |
Ty, AssumedConstantRange.getLower())), |
--- |
9022 |
Ty, AssumedConstantRange.getLower())), |
--- |
| 9023 |
ConstantAsMetadata::get(ConstantInt::get( |
0 |
9023 |
ConstantAsMetadata::get(ConstantInt::get( |
0 |
| 9024 |
Ty, AssumedConstantRange.getUpper()))}; |
0 |
9024 |
Ty, AssumedConstantRange.getUpper()))}; |
0 |
| 9025 |
return MDNode::get(Ctx, LowAndHigh); |
0 |
9025 |
return MDNode::get(Ctx, LowAndHigh); |
0 |
| 9026 |
} |
--- |
9026 |
} |
--- |
| 9027 |
|
--- |
9027 |
|
--- |
| 9028 |
/// Return true if \p Assumed is included in \p KnownRanges. |
--- |
9028 |
/// Return true if \p Assumed is included in \p KnownRanges. |
--- |
| 9029 |
static bool isBetterRange(const ConstantRange &Assumed, MDNode *KnownRanges) { |
0 |
9029 |
static bool isBetterRange(const ConstantRange &Assumed, MDNode *KnownRanges) { |
0 |
| 9030 |
|
--- |
9030 |
|
--- |
| 9031 |
if (Assumed.isFullSet()) |
0 |
9031 |
if (Assumed.isFullSet()) |
0 |
| 9032 |
return false; |
0 |
9032 |
return false; |
0 |
| 9033 |
|
--- |
9033 |
|
--- |
| 9034 |
if (!KnownRanges) |
0 |
9034 |
if (!KnownRanges) |
0 |
| 9035 |
return true; |
0 |
9035 |
return true; |
0 |
| 9036 |
|
--- |
9036 |
|
--- |
| 9037 |
// If multiple ranges are annotated in IR, we give up to annotate assumed |
--- |
9037 |
// If multiple ranges are annotated in IR, we give up to annotate assumed |
--- |
| 9038 |
// range for now. |
--- |
9038 |
// range for now. |
--- |
| 9039 |
|
--- |
9039 |
|
--- |
| 9040 |
// TODO: If there exists a known range which containts assumed range, we |
--- |
9040 |
// TODO: If there exists a known range which containts assumed range, we |
--- |
| 9041 |
// can say assumed range is better. |
--- |
9041 |
// can say assumed range is better. |
--- |
| 9042 |
if (KnownRanges->getNumOperands() > 2) |
0 |
9042 |
if (KnownRanges->getNumOperands() > 2) |
0 |
| 9043 |
return false; |
0 |
9043 |
return false; |
0 |
| 9044 |
|
--- |
9044 |
|
--- |
| 9045 |
ConstantInt *Lower = |
--- |
9045 |
ConstantInt *Lower = |
--- |
| 9046 |
mdconst::extract(KnownRanges->getOperand(0)); |
0 |
9046 |
mdconst::extract(KnownRanges->getOperand(0)); |
0 |
| 9047 |
ConstantInt *Upper = |
--- |
9047 |
ConstantInt *Upper = |
--- |
| 9048 |
mdconst::extract(KnownRanges->getOperand(1)); |
0 |
9048 |
mdconst::extract(KnownRanges->getOperand(1)); |
0 |
| 9049 |
|
--- |
9049 |
|
--- |
| 9050 |
ConstantRange Known(Lower->getValue(), Upper->getValue()); |
0 |
9050 |
ConstantRange Known(Lower->getValue(), Upper->getValue()); |
0 |
| 9051 |
return Known.contains(Assumed) && Known != Assumed; |
0 |
9051 |
return Known.contains(Assumed) && Known != Assumed; |
0 |
| 9052 |
} |
0 |
9052 |
} |
0 |
| 9053 |
|
--- |
9053 |
|
--- |
| 9054 |
/// Helper function to set range metadata. |
--- |
9054 |
/// Helper function to set range metadata. |
--- |
| 9055 |
static bool |
--- |
9055 |
static bool |
--- |
| 9056 |
setRangeMetadataIfisBetterRange(Instruction *I, |
0 |
9056 |
setRangeMetadataIfisBetterRange(Instruction *I, |
0 |
| 9057 |
const ConstantRange &AssumedConstantRange) { |
--- |
9057 |
const ConstantRange &AssumedConstantRange) { |
--- |
| 9058 |
auto *OldRangeMD = I->getMetadata(LLVMContext::MD_range); |
0 |
9058 |
auto *OldRangeMD = I->getMetadata(LLVMContext::MD_range); |
0 |
| 9059 |
if (isBetterRange(AssumedConstantRange, OldRangeMD)) { |
0 |
9059 |
if (isBetterRange(AssumedConstantRange, OldRangeMD)) { |
0 |
| 9060 |
if (!AssumedConstantRange.isEmptySet()) { |
0 |
9060 |
if (!AssumedConstantRange.isEmptySet()) { |
0 |
| 9061 |
I->setMetadata(LLVMContext::MD_range, |
0 |
9061 |
I->setMetadata(LLVMContext::MD_range, |
0 |
| 9062 |
getMDNodeForConstantRange(I->getType(), I->getContext(), |
--- |
9062 |
getMDNodeForConstantRange(I->getType(), I->getContext(), |
--- |
| 9063 |
AssumedConstantRange)); |
--- |
9063 |
AssumedConstantRange)); |
--- |
| 9064 |
return true; |
0 |
9064 |
return true; |
0 |
| 9065 |
} |
--- |
9065 |
} |
--- |
| 9066 |
} |
--- |
9066 |
} |
--- |
| 9067 |
return false; |
0 |
9067 |
return false; |
0 |
| 9068 |
} |
--- |
9068 |
} |
--- |
| 9069 |
|
--- |
9069 |
|
--- |
| 9070 |
/// See AbstractAttribute::manifest() |
--- |
9070 |
/// See AbstractAttribute::manifest() |
--- |
| 9071 |
ChangeStatus manifest(Attributor &A) override { |
0 |
9071 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 9072 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
9072 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 9073 |
ConstantRange AssumedConstantRange = getAssumedConstantRange(A); |
0 |
9073 |
ConstantRange AssumedConstantRange = getAssumedConstantRange(A); |
0 |
| 9074 |
assert(!AssumedConstantRange.isFullSet() && "Invalid state"); |
0 |
9074 |
assert(!AssumedConstantRange.isFullSet() && "Invalid state"); |
0 |
| 9075 |
|
--- |
9075 |
|
--- |
| 9076 |
auto &V = getAssociatedValue(); |
0 |
9076 |
auto &V = getAssociatedValue(); |
0 |
| 9077 |
if (!AssumedConstantRange.isEmptySet() && |
0 |
9077 |
if (!AssumedConstantRange.isEmptySet() && |
0 |
| 9078 |
!AssumedConstantRange.isSingleElement()) { |
0 |
9078 |
!AssumedConstantRange.isSingleElement()) { |
0 |
| 9079 |
if (Instruction *I = dyn_cast(&V)) { |
0 |
9079 |
if (Instruction *I = dyn_cast(&V)) { |
0 |
| 9080 |
assert(I == getCtxI() && "Should not annotate an instruction which is " |
0 |
9080 |
assert(I == getCtxI() && "Should not annotate an instruction which is " |
0 |
| 9081 |
"not the context instruction"); |
--- |
9081 |
"not the context instruction"); |
--- |
| 9082 |
if (isa(I) || isa(I)) |
0 |
9082 |
if (isa(I) || isa(I)) |
0 |
| 9083 |
if (setRangeMetadataIfisBetterRange(I, AssumedConstantRange)) |
0 |
9083 |
if (setRangeMetadataIfisBetterRange(I, AssumedConstantRange)) |
0 |
| 9084 |
Changed = ChangeStatus::CHANGED; |
0 |
9084 |
Changed = ChangeStatus::CHANGED; |
0 |
| 9085 |
} |
--- |
9085 |
} |
--- |
| 9086 |
} |
--- |
9086 |
} |
--- |
| 9087 |
|
--- |
9087 |
|
--- |
| 9088 |
return Changed; |
0 |
9088 |
return Changed; |
0 |
| 9089 |
} |
0 |
9089 |
} |
0 |
| 9090 |
}; |
--- |
9090 |
}; |
--- |
| 9091 |
|
--- |
9091 |
|
--- |
| 9092 |
struct AAValueConstantRangeArgument final |
--- |
9092 |
struct AAValueConstantRangeArgument final |
--- |
| 9093 |
: AAArgumentFromCallSiteArguments< |
--- |
9093 |
: AAArgumentFromCallSiteArguments< |
--- |
| 9094 |
AAValueConstantRange, AAValueConstantRangeImpl, IntegerRangeState, |
--- |
9094 |
AAValueConstantRange, AAValueConstantRangeImpl, IntegerRangeState, |
--- |
| 9095 |
true /* BridgeCallBaseContext */> { |
--- |
9095 |
true /* BridgeCallBaseContext */> { |
--- |
| 9096 |
using Base = AAArgumentFromCallSiteArguments< |
--- |
9096 |
using Base = AAArgumentFromCallSiteArguments< |
--- |
| 9097 |
AAValueConstantRange, AAValueConstantRangeImpl, IntegerRangeState, |
--- |
9097 |
AAValueConstantRange, AAValueConstantRangeImpl, IntegerRangeState, |
--- |
| 9098 |
true /* BridgeCallBaseContext */>; |
--- |
9098 |
true /* BridgeCallBaseContext */>; |
--- |
| 9099 |
AAValueConstantRangeArgument(const IRPosition &IRP, Attributor &A) |
0 |
9099 |
AAValueConstantRangeArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 9100 |
: Base(IRP, A) {} |
0 |
9100 |
: Base(IRP, A) {} |
0 |
| 9101 |
|
--- |
9101 |
|
--- |
| 9102 |
/// See AbstractAttribute::trackStatistics() |
--- |
9102 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9103 |
void trackStatistics() const override { |
0 |
9103 |
void trackStatistics() const override { |
0 |
| 9104 |
STATS_DECLTRACK_ARG_ATTR(value_range) |
0 |
9104 |
STATS_DECLTRACK_ARG_ATTR(value_range) |
0 |
| 9105 |
} |
0 |
9105 |
} |
0 |
| 9106 |
}; |
--- |
9106 |
}; |
--- |
| 9107 |
|
--- |
9107 |
|
--- |
| 9108 |
struct AAValueConstantRangeReturned |
--- |
9108 |
struct AAValueConstantRangeReturned |
--- |
| 9109 |
: AAReturnedFromReturnedValues
| --- |
9109 |
: AAReturnedFromReturnedValues
| --- |
| |
| 9110 |
AAValueConstantRangeImpl, |
--- |
9110 |
AAValueConstantRangeImpl, |
--- |
| 9111 |
AAValueConstantRangeImpl::StateType, |
--- |
9111 |
AAValueConstantRangeImpl::StateType, |
--- |
| 9112 |
/* PropogateCallBaseContext */ true> { |
--- |
9112 |
/* PropogateCallBaseContext */ true> { |
--- |
| 9113 |
using Base = |
--- |
9113 |
using Base = |
--- |
| 9114 |
AAReturnedFromReturnedValues
| --- |
9114 |
AAReturnedFromReturnedValues
| --- |
| |
| 9115 |
AAValueConstantRangeImpl, |
--- |
9115 |
AAValueConstantRangeImpl, |
--- |
| 9116 |
AAValueConstantRangeImpl::StateType, |
--- |
9116 |
AAValueConstantRangeImpl::StateType, |
--- |
| 9117 |
/* PropogateCallBaseContext */ true>; |
--- |
9117 |
/* PropogateCallBaseContext */ true>; |
--- |
| 9118 |
AAValueConstantRangeReturned(const IRPosition &IRP, Attributor &A) |
0 |
9118 |
AAValueConstantRangeReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 9119 |
: Base(IRP, A) {} |
0 |
9119 |
: Base(IRP, A) {} |
0 |
| 9120 |
|
--- |
9120 |
|
--- |
| 9121 |
/// See AbstractAttribute::initialize(...). |
--- |
9121 |
/// See AbstractAttribute::initialize(...). |
--- |
| 9122 |
void initialize(Attributor &A) override { |
0 |
9122 |
void initialize(Attributor &A) override { |
0 |
| 9123 |
if (!A.isFunctionIPOAmendable(*getAssociatedFunction())) |
0 |
9123 |
if (!A.isFunctionIPOAmendable(*getAssociatedFunction())) |
0 |
| 9124 |
indicatePessimisticFixpoint(); |
0 |
9124 |
indicatePessimisticFixpoint(); |
0 |
| 9125 |
} |
0 |
9125 |
} |
0 |
| 9126 |
|
--- |
9126 |
|
--- |
| 9127 |
/// See AbstractAttribute::trackStatistics() |
--- |
9127 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9128 |
void trackStatistics() const override { |
0 |
9128 |
void trackStatistics() const override { |
0 |
| 9129 |
STATS_DECLTRACK_FNRET_ATTR(value_range) |
0 |
9129 |
STATS_DECLTRACK_FNRET_ATTR(value_range) |
0 |
| 9130 |
} |
0 |
9130 |
} |
0 |
| 9131 |
}; |
--- |
9131 |
}; |
--- |
| 9132 |
|
--- |
9132 |
|
--- |
| 9133 |
struct AAValueConstantRangeFloating : AAValueConstantRangeImpl { |
--- |
9133 |
struct AAValueConstantRangeFloating : AAValueConstantRangeImpl { |
--- |
| 9134 |
AAValueConstantRangeFloating(const IRPosition &IRP, Attributor &A) |
0 |
9134 |
AAValueConstantRangeFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 9135 |
: AAValueConstantRangeImpl(IRP, A) {} |
0 |
9135 |
: AAValueConstantRangeImpl(IRP, A) {} |
0 |
| 9136 |
|
--- |
9136 |
|
--- |
| 9137 |
/// See AbstractAttribute::initialize(...). |
--- |
9137 |
/// See AbstractAttribute::initialize(...). |
--- |
| 9138 |
void initialize(Attributor &A) override { |
0 |
9138 |
void initialize(Attributor &A) override { |
0 |
| 9139 |
AAValueConstantRangeImpl::initialize(A); |
0 |
9139 |
AAValueConstantRangeImpl::initialize(A); |
0 |
| 9140 |
if (isAtFixpoint()) |
0 |
9140 |
if (isAtFixpoint()) |
0 |
| 9141 |
return; |
0 |
9141 |
return; |
0 |
| 9142 |
|
--- |
9142 |
|
--- |
| 9143 |
Value &V = getAssociatedValue(); |
0 |
9143 |
Value &V = getAssociatedValue(); |
0 |
| 9144 |
|
--- |
9144 |
|
--- |
| 9145 |
if (auto *C = dyn_cast(&V)) { |
0 |
9145 |
if (auto *C = dyn_cast(&V)) { |
0 |
| 9146 |
unionAssumed(ConstantRange(C->getValue())); |
0 |
9146 |
unionAssumed(ConstantRange(C->getValue())); |
0 |
| 9147 |
indicateOptimisticFixpoint(); |
0 |
9147 |
indicateOptimisticFixpoint(); |
0 |
| 9148 |
return; |
0 |
9148 |
return; |
0 |
| 9149 |
} |
--- |
9149 |
} |
--- |
| 9150 |
|
--- |
9150 |
|
--- |
| 9151 |
if (isa(&V)) { |
0 |
9151 |
if (isa(&V)) { |
0 |
| 9152 |
// Collapse the undef state to 0. |
--- |
9152 |
// Collapse the undef state to 0. |
--- |
| 9153 |
unionAssumed(ConstantRange(APInt(getBitWidth(), 0))); |
0 |
9153 |
unionAssumed(ConstantRange(APInt(getBitWidth(), 0))); |
0 |
| 9154 |
indicateOptimisticFixpoint(); |
0 |
9154 |
indicateOptimisticFixpoint(); |
0 |
| 9155 |
return; |
0 |
9155 |
return; |
0 |
| 9156 |
} |
--- |
9156 |
} |
--- |
| 9157 |
|
--- |
9157 |
|
--- |
| 9158 |
if (isa(&V)) |
0 |
9158 |
if (isa(&V)) |
0 |
| 9159 |
return; |
0 |
9159 |
return; |
0 |
| 9160 |
|
--- |
9160 |
|
--- |
| 9161 |
if (isa(&V) || isa(&V) || isa(&V)) |
0 |
9161 |
if (isa(&V) || isa(&V) || isa(&V)) |
0 |
| 9162 |
return; |
0 |
9162 |
return; |
0 |
| 9163 |
|
--- |
9163 |
|
--- |
| 9164 |
// If it is a load instruction with range metadata, use it. |
--- |
9164 |
// If it is a load instruction with range metadata, use it. |
--- |
| 9165 |
if (LoadInst *LI = dyn_cast(&V)) |
0 |
9165 |
if (LoadInst *LI = dyn_cast(&V)) |
0 |
| 9166 |
if (auto *RangeMD = LI->getMetadata(LLVMContext::MD_range)) { |
0 |
9166 |
if (auto *RangeMD = LI->getMetadata(LLVMContext::MD_range)) { |
0 |
| 9167 |
intersectKnown(getConstantRangeFromMetadata(*RangeMD)); |
0 |
9167 |
intersectKnown(getConstantRangeFromMetadata(*RangeMD)); |
0 |
| 9168 |
return; |
0 |
9168 |
return; |
0 |
| 9169 |
} |
--- |
9169 |
} |
--- |
| 9170 |
|
--- |
9170 |
|
--- |
| 9171 |
// We can work with PHI and select instruction as we traverse their operands |
--- |
9171 |
// We can work with PHI and select instruction as we traverse their operands |
--- |
| 9172 |
// during update. |
--- |
9172 |
// during update. |
--- |
| 9173 |
if (isa(V) || isa(V)) |
0 |
9173 |
if (isa(V) || isa(V)) |
0 |
| 9174 |
return; |
0 |
9174 |
return; |
0 |
| 9175 |
|
--- |
9175 |
|
--- |
| 9176 |
// Otherwise we give up. |
--- |
9176 |
// Otherwise we give up. |
--- |
| 9177 |
indicatePessimisticFixpoint(); |
0 |
9177 |
indicatePessimisticFixpoint(); |
0 |
| 9178 |
|
--- |
9178 |
|
--- |
| 9179 |
LLVM_DEBUG(dbgs() << "[AAValueConstantRange] We give up: " |
0 |
9179 |
LLVM_DEBUG(dbgs() << "[AAValueConstantRange] We give up: " |
0 |
| 9180 |
<< getAssociatedValue() << "\n"); |
--- |
9180 |
<< getAssociatedValue() << "\n"); |
--- |
| 9181 |
} |
--- |
9181 |
} |
--- |
| 9182 |
|
--- |
9182 |
|
--- |
| 9183 |
bool calculateBinaryOperator( |
0 |
9183 |
bool calculateBinaryOperator( |
0 |
| 9184 |
Attributor &A, BinaryOperator *BinOp, IntegerRangeState &T, |
--- |
9184 |
Attributor &A, BinaryOperator *BinOp, IntegerRangeState &T, |
--- |
| 9185 |
const Instruction *CtxI, |
--- |
9185 |
const Instruction *CtxI, |
--- |
| 9186 |
SmallVectorImpl &QuerriedAAs) { |
--- |
9186 |
SmallVectorImpl &QuerriedAAs) { |
--- |
| 9187 |
Value *LHS = BinOp->getOperand(0); |
0 |
9187 |
Value *LHS = BinOp->getOperand(0); |
0 |
| 9188 |
Value *RHS = BinOp->getOperand(1); |
0 |
9188 |
Value *RHS = BinOp->getOperand(1); |
0 |
| 9189 |
|
--- |
9189 |
|
--- |
| 9190 |
// Simplify the operands first. |
--- |
9190 |
// Simplify the operands first. |
--- |
| 9191 |
bool UsedAssumedInformation = false; |
0 |
9191 |
bool UsedAssumedInformation = false; |
0 |
| 9192 |
const auto &SimplifiedLHS = A.getAssumedSimplified( |
0 |
9192 |
const auto &SimplifiedLHS = A.getAssumedSimplified( |
0 |
| 9193 |
IRPosition::value(*LHS, getCallBaseContext()), *this, |
0 |
9193 |
IRPosition::value(*LHS, getCallBaseContext()), *this, |
0 |
| 9194 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
9194 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
| 9195 |
if (!SimplifiedLHS.has_value()) |
0 |
9195 |
if (!SimplifiedLHS.has_value()) |
0 |
| 9196 |
return true; |
0 |
9196 |
return true; |
0 |
| 9197 |
if (!*SimplifiedLHS) |
0 |
9197 |
if (!*SimplifiedLHS) |
0 |
| 9198 |
return false; |
0 |
9198 |
return false; |
0 |
| 9199 |
LHS = *SimplifiedLHS; |
0 |
9199 |
LHS = *SimplifiedLHS; |
0 |
| 9200 |
|
--- |
9200 |
|
--- |
| 9201 |
const auto &SimplifiedRHS = A.getAssumedSimplified( |
0 |
9201 |
const auto &SimplifiedRHS = A.getAssumedSimplified( |
0 |
| 9202 |
IRPosition::value(*RHS, getCallBaseContext()), *this, |
0 |
9202 |
IRPosition::value(*RHS, getCallBaseContext()), *this, |
0 |
| 9203 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
9203 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
| 9204 |
if (!SimplifiedRHS.has_value()) |
0 |
9204 |
if (!SimplifiedRHS.has_value()) |
0 |
| 9205 |
return true; |
0 |
9205 |
return true; |
0 |
| 9206 |
if (!*SimplifiedRHS) |
0 |
9206 |
if (!*SimplifiedRHS) |
0 |
| 9207 |
return false; |
0 |
9207 |
return false; |
0 |
| 9208 |
RHS = *SimplifiedRHS; |
0 |
9208 |
RHS = *SimplifiedRHS; |
0 |
| 9209 |
|
--- |
9209 |
|
--- |
| 9210 |
// TODO: Allow non integers as well. |
--- |
9210 |
// TODO: Allow non integers as well. |
--- |
| 9211 |
if (!LHS->getType()->isIntegerTy() || !RHS->getType()->isIntegerTy()) |
0 |
9211 |
if (!LHS->getType()->isIntegerTy() || !RHS->getType()->isIntegerTy()) |
0 |
| 9212 |
return false; |
0 |
9212 |
return false; |
0 |
| 9213 |
|
--- |
9213 |
|
--- |
| 9214 |
auto *LHSAA = A.getAAFor( |
0 |
9214 |
auto *LHSAA = A.getAAFor( |
0 |
| 9215 |
*this, IRPosition::value(*LHS, getCallBaseContext()), |
0 |
9215 |
*this, IRPosition::value(*LHS, getCallBaseContext()), |
0 |
| 9216 |
DepClassTy::REQUIRED); |
--- |
9216 |
DepClassTy::REQUIRED); |
--- |
| 9217 |
if (!LHSAA) |
0 |
9217 |
if (!LHSAA) |
0 |
| 9218 |
return false; |
0 |
9218 |
return false; |
0 |
| 9219 |
QuerriedAAs.push_back(LHSAA); |
0 |
9219 |
QuerriedAAs.push_back(LHSAA); |
0 |
| 9220 |
auto LHSAARange = LHSAA->getAssumedConstantRange(A, CtxI); |
0 |
9220 |
auto LHSAARange = LHSAA->getAssumedConstantRange(A, CtxI); |
0 |
| 9221 |
|
--- |
9221 |
|
--- |
| 9222 |
auto *RHSAA = A.getAAFor( |
0 |
9222 |
auto *RHSAA = A.getAAFor( |
0 |
| 9223 |
*this, IRPosition::value(*RHS, getCallBaseContext()), |
0 |
9223 |
*this, IRPosition::value(*RHS, getCallBaseContext()), |
0 |
| 9224 |
DepClassTy::REQUIRED); |
--- |
9224 |
DepClassTy::REQUIRED); |
--- |
| 9225 |
if (!RHSAA) |
0 |
9225 |
if (!RHSAA) |
0 |
| 9226 |
return false; |
0 |
9226 |
return false; |
0 |
| 9227 |
QuerriedAAs.push_back(RHSAA); |
0 |
9227 |
QuerriedAAs.push_back(RHSAA); |
0 |
| 9228 |
auto RHSAARange = RHSAA->getAssumedConstantRange(A, CtxI); |
0 |
9228 |
auto RHSAARange = RHSAA->getAssumedConstantRange(A, CtxI); |
0 |
| 9229 |
|
--- |
9229 |
|
--- |
| 9230 |
auto AssumedRange = LHSAARange.binaryOp(BinOp->getOpcode(), RHSAARange); |
0 |
9230 |
auto AssumedRange = LHSAARange.binaryOp(BinOp->getOpcode(), RHSAARange); |
0 |
| 9231 |
|
--- |
9231 |
|
--- |
| 9232 |
T.unionAssumed(AssumedRange); |
0 |
9232 |
T.unionAssumed(AssumedRange); |
0 |
| 9233 |
|
--- |
9233 |
|
--- |
| 9234 |
// TODO: Track a known state too. |
--- |
9234 |
// TODO: Track a known state too. |
--- |
| 9235 |
|
--- |
9235 |
|
--- |
| 9236 |
return T.isValidState(); |
0 |
9236 |
return T.isValidState(); |
0 |
| 9237 |
} |
0 |
9237 |
} |
0 |
| 9238 |
|
--- |
9238 |
|
--- |
| 9239 |
bool calculateCastInst( |
0 |
9239 |
bool calculateCastInst( |
0 |
| 9240 |
Attributor &A, CastInst *CastI, IntegerRangeState &T, |
--- |
9240 |
Attributor &A, CastInst *CastI, IntegerRangeState &T, |
--- |
| 9241 |
const Instruction *CtxI, |
--- |
9241 |
const Instruction *CtxI, |
--- |
| 9242 |
SmallVectorImpl &QuerriedAAs) { |
--- |
9242 |
SmallVectorImpl &QuerriedAAs) { |
--- |
| 9243 |
assert(CastI->getNumOperands() == 1 && "Expected cast to be unary!"); |
0 |
9243 |
assert(CastI->getNumOperands() == 1 && "Expected cast to be unary!"); |
0 |
| 9244 |
// TODO: Allow non integers as well. |
--- |
9244 |
// TODO: Allow non integers as well. |
--- |
| 9245 |
Value *OpV = CastI->getOperand(0); |
0 |
9245 |
Value *OpV = CastI->getOperand(0); |
0 |
| 9246 |
|
--- |
9246 |
|
--- |
| 9247 |
// Simplify the operand first. |
--- |
9247 |
// Simplify the operand first. |
--- |
| 9248 |
bool UsedAssumedInformation = false; |
0 |
9248 |
bool UsedAssumedInformation = false; |
0 |
| 9249 |
const auto &SimplifiedOpV = A.getAssumedSimplified( |
0 |
9249 |
const auto &SimplifiedOpV = A.getAssumedSimplified( |
0 |
| 9250 |
IRPosition::value(*OpV, getCallBaseContext()), *this, |
0 |
9250 |
IRPosition::value(*OpV, getCallBaseContext()), *this, |
0 |
| 9251 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
9251 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
| 9252 |
if (!SimplifiedOpV.has_value()) |
0 |
9252 |
if (!SimplifiedOpV.has_value()) |
0 |
| 9253 |
return true; |
0 |
9253 |
return true; |
0 |
| 9254 |
if (!*SimplifiedOpV) |
0 |
9254 |
if (!*SimplifiedOpV) |
0 |
| 9255 |
return false; |
0 |
9255 |
return false; |
0 |
| 9256 |
OpV = *SimplifiedOpV; |
0 |
9256 |
OpV = *SimplifiedOpV; |
0 |
| 9257 |
|
--- |
9257 |
|
--- |
| 9258 |
if (!OpV->getType()->isIntegerTy()) |
0 |
9258 |
if (!OpV->getType()->isIntegerTy()) |
0 |
| 9259 |
return false; |
0 |
9259 |
return false; |
0 |
| 9260 |
|
--- |
9260 |
|
--- |
| 9261 |
auto *OpAA = A.getAAFor( |
0 |
9261 |
auto *OpAA = A.getAAFor( |
0 |
| 9262 |
*this, IRPosition::value(*OpV, getCallBaseContext()), |
0 |
9262 |
*this, IRPosition::value(*OpV, getCallBaseContext()), |
0 |
| 9263 |
DepClassTy::REQUIRED); |
--- |
9263 |
DepClassTy::REQUIRED); |
--- |
| 9264 |
if (!OpAA) |
0 |
9264 |
if (!OpAA) |
0 |
| 9265 |
return false; |
0 |
9265 |
return false; |
0 |
| 9266 |
QuerriedAAs.push_back(OpAA); |
0 |
9266 |
QuerriedAAs.push_back(OpAA); |
0 |
| 9267 |
T.unionAssumed(OpAA->getAssumed().castOp(CastI->getOpcode(), |
0 |
9267 |
T.unionAssumed(OpAA->getAssumed().castOp(CastI->getOpcode(), |
0 |
| 9268 |
getState().getBitWidth())); |
0 |
9268 |
getState().getBitWidth())); |
0 |
| 9269 |
return T.isValidState(); |
0 |
9269 |
return T.isValidState(); |
0 |
| 9270 |
} |
--- |
9270 |
} |
--- |
| 9271 |
|
--- |
9271 |
|
--- |
| 9272 |
bool |
--- |
9272 |
bool |
--- |
| 9273 |
calculateCmpInst(Attributor &A, CmpInst *CmpI, IntegerRangeState &T, |
0 |
9273 |
calculateCmpInst(Attributor &A, CmpInst *CmpI, IntegerRangeState &T, |
0 |
| 9274 |
const Instruction *CtxI, |
--- |
9274 |
const Instruction *CtxI, |
--- |
| 9275 |
SmallVectorImpl &QuerriedAAs) { |
--- |
9275 |
SmallVectorImpl &QuerriedAAs) { |
--- |
| 9276 |
Value *LHS = CmpI->getOperand(0); |
0 |
9276 |
Value *LHS = CmpI->getOperand(0); |
0 |
| 9277 |
Value *RHS = CmpI->getOperand(1); |
0 |
9277 |
Value *RHS = CmpI->getOperand(1); |
0 |
| 9278 |
|
--- |
9278 |
|
--- |
| 9279 |
// Simplify the operands first. |
--- |
9279 |
// Simplify the operands first. |
--- |
| 9280 |
bool UsedAssumedInformation = false; |
0 |
9280 |
bool UsedAssumedInformation = false; |
0 |
| 9281 |
const auto &SimplifiedLHS = A.getAssumedSimplified( |
0 |
9281 |
const auto &SimplifiedLHS = A.getAssumedSimplified( |
0 |
| 9282 |
IRPosition::value(*LHS, getCallBaseContext()), *this, |
0 |
9282 |
IRPosition::value(*LHS, getCallBaseContext()), *this, |
0 |
| 9283 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
9283 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
| 9284 |
if (!SimplifiedLHS.has_value()) |
0 |
9284 |
if (!SimplifiedLHS.has_value()) |
0 |
| 9285 |
return true; |
0 |
9285 |
return true; |
0 |
| 9286 |
if (!*SimplifiedLHS) |
0 |
9286 |
if (!*SimplifiedLHS) |
0 |
| 9287 |
return false; |
0 |
9287 |
return false; |
0 |
| 9288 |
LHS = *SimplifiedLHS; |
0 |
9288 |
LHS = *SimplifiedLHS; |
0 |
| 9289 |
|
--- |
9289 |
|
--- |
| 9290 |
const auto &SimplifiedRHS = A.getAssumedSimplified( |
0 |
9290 |
const auto &SimplifiedRHS = A.getAssumedSimplified( |
0 |
| 9291 |
IRPosition::value(*RHS, getCallBaseContext()), *this, |
0 |
9291 |
IRPosition::value(*RHS, getCallBaseContext()), *this, |
0 |
| 9292 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
9292 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
| 9293 |
if (!SimplifiedRHS.has_value()) |
0 |
9293 |
if (!SimplifiedRHS.has_value()) |
0 |
| 9294 |
return true; |
0 |
9294 |
return true; |
0 |
| 9295 |
if (!*SimplifiedRHS) |
0 |
9295 |
if (!*SimplifiedRHS) |
0 |
| 9296 |
return false; |
0 |
9296 |
return false; |
0 |
| 9297 |
RHS = *SimplifiedRHS; |
0 |
9297 |
RHS = *SimplifiedRHS; |
0 |
| 9298 |
|
--- |
9298 |
|
--- |
| 9299 |
// TODO: Allow non integers as well. |
--- |
9299 |
// TODO: Allow non integers as well. |
--- |
| 9300 |
if (!LHS->getType()->isIntegerTy() || !RHS->getType()->isIntegerTy()) |
0 |
9300 |
if (!LHS->getType()->isIntegerTy() || !RHS->getType()->isIntegerTy()) |
0 |
| 9301 |
return false; |
0 |
9301 |
return false; |
0 |
| 9302 |
|
--- |
9302 |
|
--- |
| 9303 |
auto *LHSAA = A.getAAFor( |
0 |
9303 |
auto *LHSAA = A.getAAFor( |
0 |
| 9304 |
*this, IRPosition::value(*LHS, getCallBaseContext()), |
0 |
9304 |
*this, IRPosition::value(*LHS, getCallBaseContext()), |
0 |
| 9305 |
DepClassTy::REQUIRED); |
--- |
9305 |
DepClassTy::REQUIRED); |
--- |
| 9306 |
if (!LHSAA) |
0 |
9306 |
if (!LHSAA) |
0 |
| 9307 |
return false; |
0 |
9307 |
return false; |
0 |
| 9308 |
QuerriedAAs.push_back(LHSAA); |
0 |
9308 |
QuerriedAAs.push_back(LHSAA); |
0 |
| 9309 |
auto *RHSAA = A.getAAFor( |
0 |
9309 |
auto *RHSAA = A.getAAFor( |
0 |
| 9310 |
*this, IRPosition::value(*RHS, getCallBaseContext()), |
0 |
9310 |
*this, IRPosition::value(*RHS, getCallBaseContext()), |
0 |
| 9311 |
DepClassTy::REQUIRED); |
--- |
9311 |
DepClassTy::REQUIRED); |
--- |
| 9312 |
if (!RHSAA) |
0 |
9312 |
if (!RHSAA) |
0 |
| 9313 |
return false; |
0 |
9313 |
return false; |
0 |
| 9314 |
QuerriedAAs.push_back(RHSAA); |
0 |
9314 |
QuerriedAAs.push_back(RHSAA); |
0 |
| 9315 |
auto LHSAARange = LHSAA->getAssumedConstantRange(A, CtxI); |
0 |
9315 |
auto LHSAARange = LHSAA->getAssumedConstantRange(A, CtxI); |
0 |
| 9316 |
auto RHSAARange = RHSAA->getAssumedConstantRange(A, CtxI); |
0 |
9316 |
auto RHSAARange = RHSAA->getAssumedConstantRange(A, CtxI); |
0 |
| 9317 |
|
--- |
9317 |
|
--- |
| 9318 |
// If one of them is empty set, we can't decide. |
--- |
9318 |
// If one of them is empty set, we can't decide. |
--- |
| 9319 |
if (LHSAARange.isEmptySet() || RHSAARange.isEmptySet()) |
0 |
9319 |
if (LHSAARange.isEmptySet() || RHSAARange.isEmptySet()) |
0 |
| 9320 |
return true; |
0 |
9320 |
return true; |
0 |
| 9321 |
|
--- |
9321 |
|
--- |
| 9322 |
bool MustTrue = false, MustFalse = false; |
0 |
9322 |
bool MustTrue = false, MustFalse = false; |
0 |
| 9323 |
|
--- |
9323 |
|
--- |
| 9324 |
auto AllowedRegion = |
--- |
9324 |
auto AllowedRegion = |
--- |
| 9325 |
ConstantRange::makeAllowedICmpRegion(CmpI->getPredicate(), RHSAARange); |
0 |
9325 |
ConstantRange::makeAllowedICmpRegion(CmpI->getPredicate(), RHSAARange); |
0 |
| 9326 |
|
--- |
9326 |
|
--- |
| 9327 |
if (AllowedRegion.intersectWith(LHSAARange).isEmptySet()) |
0 |
9327 |
if (AllowedRegion.intersectWith(LHSAARange).isEmptySet()) |
0 |
| 9328 |
MustFalse = true; |
0 |
9328 |
MustFalse = true; |
0 |
| 9329 |
|
--- |
9329 |
|
--- |
| 9330 |
if (LHSAARange.icmp(CmpI->getPredicate(), RHSAARange)) |
0 |
9330 |
if (LHSAARange.icmp(CmpI->getPredicate(), RHSAARange)) |
0 |
| 9331 |
MustTrue = true; |
0 |
9331 |
MustTrue = true; |
0 |
| 9332 |
|
--- |
9332 |
|
--- |
| 9333 |
assert((!MustTrue || !MustFalse) && |
0 |
9333 |
assert((!MustTrue || !MustFalse) && |
0 |
| 9334 |
"Either MustTrue or MustFalse should be false!"); |
--- |
9334 |
"Either MustTrue or MustFalse should be false!"); |
--- |
| 9335 |
|
--- |
9335 |
|
--- |
| 9336 |
if (MustTrue) |
0 |
9336 |
if (MustTrue) |
0 |
| 9337 |
T.unionAssumed(ConstantRange(APInt(/* numBits */ 1, /* val */ 1))); |
0 |
9337 |
T.unionAssumed(ConstantRange(APInt(/* numBits */ 1, /* val */ 1))); |
0 |
| 9338 |
else if (MustFalse) |
0 |
9338 |
else if (MustFalse) |
0 |
| 9339 |
T.unionAssumed(ConstantRange(APInt(/* numBits */ 1, /* val */ 0))); |
0 |
9339 |
T.unionAssumed(ConstantRange(APInt(/* numBits */ 1, /* val */ 0))); |
0 |
| 9340 |
else |
--- |
9340 |
else |
--- |
| 9341 |
T.unionAssumed(ConstantRange(/* BitWidth */ 1, /* isFullSet */ true)); |
0 |
9341 |
T.unionAssumed(ConstantRange(/* BitWidth */ 1, /* isFullSet */ true)); |
0 |
| 9342 |
|
--- |
9342 |
|
--- |
| 9343 |
LLVM_DEBUG(dbgs() << "[AAValueConstantRange] " << *CmpI << " after " |
0 |
9343 |
LLVM_DEBUG(dbgs() << "[AAValueConstantRange] " << *CmpI << " after " |
0 |
| 9344 |
<< (MustTrue ? "true" : (MustFalse ? "false" : "unknown")) |
--- |
9344 |
<< (MustTrue ? "true" : (MustFalse ? "false" : "unknown")) |
--- |
| 9345 |
<< ": " << T << "\n\t" << *LHSAA << "\t\n\t" |
--- |
9345 |
<< ": " << T << "\n\t" << *LHSAA << "\t\n\t" |
--- |
| 9346 |
<< *RHSAA); |
--- |
9346 |
<< *RHSAA); |
--- |
| 9347 |
|
--- |
9347 |
|
--- |
| 9348 |
// TODO: Track a known state too. |
--- |
9348 |
// TODO: Track a known state too. |
--- |
| 9349 |
return T.isValidState(); |
0 |
9349 |
return T.isValidState(); |
0 |
| 9350 |
} |
0 |
9350 |
} |
0 |
| 9351 |
|
--- |
9351 |
|
--- |
| 9352 |
/// See AbstractAttribute::updateImpl(...). |
--- |
9352 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 9353 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
9353 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 9354 |
|
--- |
9354 |
|
--- |
| 9355 |
IntegerRangeState T(getBitWidth()); |
0 |
9355 |
IntegerRangeState T(getBitWidth()); |
0 |
| 9356 |
auto VisitValueCB = [&](Value &V, const Instruction *CtxI) -> bool { |
0 |
9356 |
auto VisitValueCB = [&](Value &V, const Instruction *CtxI) -> bool { |
0 |
| 9357 |
Instruction *I = dyn_cast(&V); |
0 |
9357 |
Instruction *I = dyn_cast(&V); |
0 |
| 9358 |
if (!I || isa(I)) { |
0 |
9358 |
if (!I || isa(I)) { |
0 |
| 9359 |
|
--- |
9359 |
|
--- |
| 9360 |
// Simplify the operand first. |
--- |
9360 |
// Simplify the operand first. |
--- |
| 9361 |
bool UsedAssumedInformation = false; |
0 |
9361 |
bool UsedAssumedInformation = false; |
0 |
| 9362 |
const auto &SimplifiedOpV = A.getAssumedSimplified( |
0 |
9362 |
const auto &SimplifiedOpV = A.getAssumedSimplified( |
0 |
| 9363 |
IRPosition::value(V, getCallBaseContext()), *this, |
0 |
9363 |
IRPosition::value(V, getCallBaseContext()), *this, |
0 |
| 9364 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
9364 |
UsedAssumedInformation, AA::Interprocedural); |
0 |
| 9365 |
if (!SimplifiedOpV.has_value()) |
0 |
9365 |
if (!SimplifiedOpV.has_value()) |
0 |
| 9366 |
return true; |
0 |
9366 |
return true; |
0 |
| 9367 |
if (!*SimplifiedOpV) |
0 |
9367 |
if (!*SimplifiedOpV) |
0 |
| 9368 |
return false; |
0 |
9368 |
return false; |
0 |
| 9369 |
Value *VPtr = *SimplifiedOpV; |
0 |
9369 |
Value *VPtr = *SimplifiedOpV; |
0 |
| 9370 |
|
--- |
9370 |
|
--- |
| 9371 |
// If the value is not instruction, we query AA to Attributor. |
--- |
9371 |
// If the value is not instruction, we query AA to Attributor. |
--- |
| 9372 |
const auto *AA = A.getAAFor( |
0 |
9372 |
const auto *AA = A.getAAFor( |
0 |
| 9373 |
*this, IRPosition::value(*VPtr, getCallBaseContext()), |
0 |
9373 |
*this, IRPosition::value(*VPtr, getCallBaseContext()), |
0 |
| 9374 |
DepClassTy::REQUIRED); |
--- |
9374 |
DepClassTy::REQUIRED); |
--- |
| 9375 |
|
--- |
9375 |
|
--- |
| 9376 |
// Clamp operator is not used to utilize a program point CtxI. |
--- |
9376 |
// Clamp operator is not used to utilize a program point CtxI. |
--- |
| 9377 |
if (AA) |
0 |
9377 |
if (AA) |
0 |
| 9378 |
T.unionAssumed(AA->getAssumedConstantRange(A, CtxI)); |
0 |
9378 |
T.unionAssumed(AA->getAssumedConstantRange(A, CtxI)); |
0 |
| 9379 |
else |
--- |
9379 |
else |
--- |
| 9380 |
return false; |
0 |
9380 |
return false; |
0 |
| 9381 |
|
--- |
9381 |
|
--- |
| 9382 |
return T.isValidState(); |
0 |
9382 |
return T.isValidState(); |
0 |
| 9383 |
} |
--- |
9383 |
} |
--- |
| 9384 |
|
--- |
9384 |
|
--- |
| 9385 |
SmallVector QuerriedAAs; |
0 |
9385 |
SmallVector QuerriedAAs; |
0 |
| 9386 |
if (auto *BinOp = dyn_cast(I)) { |
0 |
9386 |
if (auto *BinOp = dyn_cast(I)) { |
0 |
| 9387 |
if (!calculateBinaryOperator(A, BinOp, T, CtxI, QuerriedAAs)) |
0 |
9387 |
if (!calculateBinaryOperator(A, BinOp, T, CtxI, QuerriedAAs)) |
0 |
| 9388 |
return false; |
0 |
9388 |
return false; |
0 |
| 9389 |
} else if (auto *CmpI = dyn_cast(I)) { |
0 |
9389 |
} else if (auto *CmpI = dyn_cast(I)) { |
0 |
| 9390 |
if (!calculateCmpInst(A, CmpI, T, CtxI, QuerriedAAs)) |
0 |
9390 |
if (!calculateCmpInst(A, CmpI, T, CtxI, QuerriedAAs)) |
0 |
| 9391 |
return false; |
0 |
9391 |
return false; |
0 |
| 9392 |
} else if (auto *CastI = dyn_cast(I)) { |
0 |
9392 |
} else if (auto *CastI = dyn_cast(I)) { |
0 |
| 9393 |
if (!calculateCastInst(A, CastI, T, CtxI, QuerriedAAs)) |
0 |
9393 |
if (!calculateCastInst(A, CastI, T, CtxI, QuerriedAAs)) |
0 |
| 9394 |
return false; |
0 |
9394 |
return false; |
0 |
| 9395 |
} else { |
--- |
9395 |
} else { |
--- |
| 9396 |
// Give up with other instructions. |
--- |
9396 |
// Give up with other instructions. |
--- |
| 9397 |
// TODO: Add other instructions |
--- |
9397 |
// TODO: Add other instructions |
--- |
| 9398 |
|
--- |
9398 |
|
--- |
| 9399 |
T.indicatePessimisticFixpoint(); |
0 |
9399 |
T.indicatePessimisticFixpoint(); |
0 |
| 9400 |
return false; |
0 |
9400 |
return false; |
0 |
| 9401 |
} |
--- |
9401 |
} |
--- |
| 9402 |
|
--- |
9402 |
|
--- |
| 9403 |
// Catch circular reasoning in a pessimistic way for now. |
--- |
9403 |
// Catch circular reasoning in a pessimistic way for now. |
--- |
| 9404 |
// TODO: Check how the range evolves and if we stripped anything, see also |
--- |
9404 |
// TODO: Check how the range evolves and if we stripped anything, see also |
--- |
| 9405 |
// AADereferenceable or AAAlign for similar situations. |
--- |
9405 |
// AADereferenceable or AAAlign for similar situations. |
--- |
| 9406 |
for (const AAValueConstantRange *QueriedAA : QuerriedAAs) { |
0 |
9406 |
for (const AAValueConstantRange *QueriedAA : QuerriedAAs) { |
0 |
| 9407 |
if (QueriedAA != this) |
0 |
9407 |
if (QueriedAA != this) |
0 |
| 9408 |
continue; |
0 |
9408 |
continue; |
0 |
| 9409 |
// If we are in a stady state we do not need to worry. |
--- |
9409 |
// If we are in a stady state we do not need to worry. |
--- |
| 9410 |
if (T.getAssumed() == getState().getAssumed()) |
0 |
9410 |
if (T.getAssumed() == getState().getAssumed()) |
0 |
| 9411 |
continue; |
0 |
9411 |
continue; |
0 |
| 9412 |
T.indicatePessimisticFixpoint(); |
0 |
9412 |
T.indicatePessimisticFixpoint(); |
0 |
| 9413 |
} |
--- |
9413 |
} |
--- |
| 9414 |
|
--- |
9414 |
|
--- |
| 9415 |
return T.isValidState(); |
0 |
9415 |
return T.isValidState(); |
0 |
| 9416 |
}; |
0 |
9416 |
}; |
0 |
| 9417 |
|
--- |
9417 |
|
--- |
| 9418 |
if (!VisitValueCB(getAssociatedValue(), getCtxI())) |
0 |
9418 |
if (!VisitValueCB(getAssociatedValue(), getCtxI())) |
0 |
| 9419 |
return indicatePessimisticFixpoint(); |
0 |
9419 |
return indicatePessimisticFixpoint(); |
0 |
| 9420 |
|
--- |
9420 |
|
--- |
| 9421 |
// Ensure that long def-use chains can't cause circular reasoning either by |
--- |
9421 |
// Ensure that long def-use chains can't cause circular reasoning either by |
--- |
| 9422 |
// introducing a cutoff below. |
--- |
9422 |
// introducing a cutoff below. |
--- |
| 9423 |
if (clampStateAndIndicateChange(getState(), T) == ChangeStatus::UNCHANGED) |
0 |
9423 |
if (clampStateAndIndicateChange(getState(), T) == ChangeStatus::UNCHANGED) |
0 |
| 9424 |
return ChangeStatus::UNCHANGED; |
0 |
9424 |
return ChangeStatus::UNCHANGED; |
0 |
| 9425 |
if (++NumChanges > MaxNumChanges) { |
0 |
9425 |
if (++NumChanges > MaxNumChanges) { |
0 |
| 9426 |
LLVM_DEBUG(dbgs() << "[AAValueConstantRange] performed " << NumChanges |
0 |
9426 |
LLVM_DEBUG(dbgs() << "[AAValueConstantRange] performed " << NumChanges |
0 |
| 9427 |
<< " but only " << MaxNumChanges |
--- |
9427 |
<< " but only " << MaxNumChanges |
--- |
| 9428 |
<< " are allowed to avoid cyclic reasoning."); |
--- |
9428 |
<< " are allowed to avoid cyclic reasoning."); |
--- |
| 9429 |
return indicatePessimisticFixpoint(); |
0 |
9429 |
return indicatePessimisticFixpoint(); |
0 |
| 9430 |
} |
--- |
9430 |
} |
--- |
| 9431 |
return ChangeStatus::CHANGED; |
0 |
9431 |
return ChangeStatus::CHANGED; |
0 |
| 9432 |
} |
0 |
9432 |
} |
0 |
| 9433 |
|
--- |
9433 |
|
--- |
| 9434 |
/// See AbstractAttribute::trackStatistics() |
--- |
9434 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9435 |
void trackStatistics() const override { |
0 |
9435 |
void trackStatistics() const override { |
0 |
| 9436 |
STATS_DECLTRACK_FLOATING_ATTR(value_range) |
0 |
9436 |
STATS_DECLTRACK_FLOATING_ATTR(value_range) |
0 |
| 9437 |
} |
0 |
9437 |
} |
0 |
| 9438 |
|
--- |
9438 |
|
--- |
| 9439 |
/// Tracker to bail after too many widening steps of the constant range. |
--- |
9439 |
/// Tracker to bail after too many widening steps of the constant range. |
--- |
| 9440 |
int NumChanges = 0; |
--- |
9440 |
int NumChanges = 0; |
--- |
| 9441 |
|
--- |
9441 |
|
--- |
| 9442 |
/// Upper bound for the number of allowed changes (=widening steps) for the |
--- |
9442 |
/// Upper bound for the number of allowed changes (=widening steps) for the |
--- |
| 9443 |
/// constant range before we give up. |
--- |
9443 |
/// constant range before we give up. |
--- |
| 9444 |
static constexpr int MaxNumChanges = 5; |
--- |
9444 |
static constexpr int MaxNumChanges = 5; |
--- |
| 9445 |
}; |
--- |
9445 |
}; |
--- |
| 9446 |
|
--- |
9446 |
|
--- |
| 9447 |
struct AAValueConstantRangeFunction : AAValueConstantRangeImpl { |
--- |
9447 |
struct AAValueConstantRangeFunction : AAValueConstantRangeImpl { |
--- |
| 9448 |
AAValueConstantRangeFunction(const IRPosition &IRP, Attributor &A) |
--- |
9448 |
AAValueConstantRangeFunction(const IRPosition &IRP, Attributor &A) |
--- |
| 9449 |
: AAValueConstantRangeImpl(IRP, A) {} |
--- |
9449 |
: AAValueConstantRangeImpl(IRP, A) {} |
--- |
| 9450 |
|
--- |
9450 |
|
--- |
| 9451 |
/// See AbstractAttribute::initialize(...). |
--- |
9451 |
/// See AbstractAttribute::initialize(...). |
--- |
| 9452 |
ChangeStatus updateImpl(Attributor &A) override { |
--- |
9452 |
ChangeStatus updateImpl(Attributor &A) override { |
--- |
| 9453 |
llvm_unreachable("AAValueConstantRange(Function|CallSite)::updateImpl will " |
--- |
9453 |
llvm_unreachable("AAValueConstantRange(Function|CallSite)::updateImpl will " |
--- |
| 9454 |
"not be called"); |
--- |
9454 |
"not be called"); |
--- |
| 9455 |
} |
--- |
9455 |
} |
--- |
| 9456 |
|
--- |
9456 |
|
--- |
| 9457 |
/// See AbstractAttribute::trackStatistics() |
--- |
9457 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9458 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(value_range) } |
--- |
9458 |
void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(value_range) } |
--- |
| 9459 |
}; |
--- |
9459 |
}; |
--- |
| 9460 |
|
--- |
9460 |
|
--- |
| 9461 |
struct AAValueConstantRangeCallSite : AAValueConstantRangeFunction { |
--- |
9461 |
struct AAValueConstantRangeCallSite : AAValueConstantRangeFunction { |
--- |
| 9462 |
AAValueConstantRangeCallSite(const IRPosition &IRP, Attributor &A) |
--- |
9462 |
AAValueConstantRangeCallSite(const IRPosition &IRP, Attributor &A) |
--- |
| 9463 |
: AAValueConstantRangeFunction(IRP, A) {} |
--- |
9463 |
: AAValueConstantRangeFunction(IRP, A) {} |
--- |
| 9464 |
|
--- |
9464 |
|
--- |
| 9465 |
/// See AbstractAttribute::trackStatistics() |
--- |
9465 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9466 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(value_range) } |
--- |
9466 |
void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(value_range) } |
--- |
| 9467 |
}; |
--- |
9467 |
}; |
--- |
| 9468 |
|
--- |
9468 |
|
--- |
| 9469 |
struct AAValueConstantRangeCallSiteReturned |
--- |
9469 |
struct AAValueConstantRangeCallSiteReturned |
--- |
| 9470 |
: AACallSiteReturnedFromReturned
| --- |
9470 |
: AACallSiteReturnedFromReturned
| --- |
| |
| 9471 |
AAValueConstantRangeImpl, |
--- |
9471 |
AAValueConstantRangeImpl, |
--- |
| 9472 |
AAValueConstantRangeImpl::StateType, |
--- |
9472 |
AAValueConstantRangeImpl::StateType, |
--- |
| 9473 |
/* IntroduceCallBaseContext */ true> { |
--- |
9473 |
/* IntroduceCallBaseContext */ true> { |
--- |
| 9474 |
AAValueConstantRangeCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
9474 |
AAValueConstantRangeCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 9475 |
: AACallSiteReturnedFromReturned
| --- |
9475 |
: AACallSiteReturnedFromReturned
| --- |
| |
| 9476 |
AAValueConstantRangeImpl, |
--- |
9476 |
AAValueConstantRangeImpl, |
--- |
| 9477 |
AAValueConstantRangeImpl::StateType, |
--- |
9477 |
AAValueConstantRangeImpl::StateType, |
--- |
| 9478 |
/* IntroduceCallBaseContext */ true>(IRP, |
--- |
9478 |
/* IntroduceCallBaseContext */ true>(IRP, |
--- |
| 9479 |
A) { |
0 |
9479 |
A) { |
0 |
| 9480 |
} |
0 |
9480 |
} |
0 |
| 9481 |
|
--- |
9481 |
|
--- |
| 9482 |
/// See AbstractAttribute::initialize(...). |
--- |
9482 |
/// See AbstractAttribute::initialize(...). |
--- |
| 9483 |
void initialize(Attributor &A) override { |
0 |
9483 |
void initialize(Attributor &A) override { |
0 |
| 9484 |
// If it is a load instruction with range metadata, use the metadata. |
--- |
9484 |
// If it is a load instruction with range metadata, use the metadata. |
--- |
| 9485 |
if (CallInst *CI = dyn_cast(&getAssociatedValue())) |
0 |
9485 |
if (CallInst *CI = dyn_cast(&getAssociatedValue())) |
0 |
| 9486 |
if (auto *RangeMD = CI->getMetadata(LLVMContext::MD_range)) |
0 |
9486 |
if (auto *RangeMD = CI->getMetadata(LLVMContext::MD_range)) |
0 |
| 9487 |
intersectKnown(getConstantRangeFromMetadata(*RangeMD)); |
0 |
9487 |
intersectKnown(getConstantRangeFromMetadata(*RangeMD)); |
0 |
| 9488 |
|
--- |
9488 |
|
--- |
| 9489 |
AAValueConstantRangeImpl::initialize(A); |
0 |
9489 |
AAValueConstantRangeImpl::initialize(A); |
0 |
| 9490 |
} |
0 |
9490 |
} |
0 |
| 9491 |
|
--- |
9491 |
|
--- |
| 9492 |
/// See AbstractAttribute::trackStatistics() |
--- |
9492 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9493 |
void trackStatistics() const override { |
0 |
9493 |
void trackStatistics() const override { |
0 |
| 9494 |
STATS_DECLTRACK_CSRET_ATTR(value_range) |
0 |
9494 |
STATS_DECLTRACK_CSRET_ATTR(value_range) |
0 |
| 9495 |
} |
0 |
9495 |
} |
0 |
| 9496 |
}; |
--- |
9496 |
}; |
--- |
| 9497 |
struct AAValueConstantRangeCallSiteArgument : AAValueConstantRangeFloating { |
--- |
9497 |
struct AAValueConstantRangeCallSiteArgument : AAValueConstantRangeFloating { |
--- |
| 9498 |
AAValueConstantRangeCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
9498 |
AAValueConstantRangeCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 9499 |
: AAValueConstantRangeFloating(IRP, A) {} |
0 |
9499 |
: AAValueConstantRangeFloating(IRP, A) {} |
0 |
| 9500 |
|
--- |
9500 |
|
--- |
| 9501 |
/// See AbstractAttribute::manifest() |
--- |
9501 |
/// See AbstractAttribute::manifest() |
--- |
| 9502 |
ChangeStatus manifest(Attributor &A) override { |
0 |
9502 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 9503 |
return ChangeStatus::UNCHANGED; |
0 |
9503 |
return ChangeStatus::UNCHANGED; |
0 |
| 9504 |
} |
--- |
9504 |
} |
--- |
| 9505 |
|
--- |
9505 |
|
--- |
| 9506 |
/// See AbstractAttribute::trackStatistics() |
--- |
9506 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9507 |
void trackStatistics() const override { |
0 |
9507 |
void trackStatistics() const override { |
0 |
| 9508 |
STATS_DECLTRACK_CSARG_ATTR(value_range) |
0 |
9508 |
STATS_DECLTRACK_CSARG_ATTR(value_range) |
0 |
| 9509 |
} |
0 |
9509 |
} |
0 |
| 9510 |
}; |
--- |
9510 |
}; |
--- |
| 9511 |
} // namespace |
--- |
9511 |
} // namespace |
--- |
| 9512 |
|
--- |
9512 |
|
--- |
| 9513 |
/// ------------------ Potential Values Attribute ------------------------- |
--- |
9513 |
/// ------------------ Potential Values Attribute ------------------------- |
--- |
| 9514 |
|
--- |
9514 |
|
--- |
| 9515 |
namespace { |
--- |
9515 |
namespace { |
--- |
| 9516 |
struct AAPotentialConstantValuesImpl : AAPotentialConstantValues { |
--- |
9516 |
struct AAPotentialConstantValuesImpl : AAPotentialConstantValues { |
--- |
| 9517 |
using StateType = PotentialConstantIntValuesState; |
--- |
9517 |
using StateType = PotentialConstantIntValuesState; |
--- |
| 9518 |
|
--- |
9518 |
|
--- |
| 9519 |
AAPotentialConstantValuesImpl(const IRPosition &IRP, Attributor &A) |
0 |
9519 |
AAPotentialConstantValuesImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 9520 |
: AAPotentialConstantValues(IRP, A) {} |
0 |
9520 |
: AAPotentialConstantValues(IRP, A) {} |
0 |
| 9521 |
|
--- |
9521 |
|
--- |
| 9522 |
/// See AbstractAttribute::initialize(..). |
--- |
9522 |
/// See AbstractAttribute::initialize(..). |
--- |
| 9523 |
void initialize(Attributor &A) override { |
0 |
9523 |
void initialize(Attributor &A) override { |
0 |
| 9524 |
if (A.hasSimplificationCallback(getIRPosition())) |
0 |
9524 |
if (A.hasSimplificationCallback(getIRPosition())) |
0 |
| 9525 |
indicatePessimisticFixpoint(); |
0 |
9525 |
indicatePessimisticFixpoint(); |
0 |
| 9526 |
else |
--- |
9526 |
else |
--- |
| 9527 |
AAPotentialConstantValues::initialize(A); |
0 |
9527 |
AAPotentialConstantValues::initialize(A); |
0 |
| 9528 |
} |
0 |
9528 |
} |
0 |
| 9529 |
|
--- |
9529 |
|
--- |
| 9530 |
bool fillSetWithConstantValues(Attributor &A, const IRPosition &IRP, SetTy &S, |
0 |
9530 |
bool fillSetWithConstantValues(Attributor &A, const IRPosition &IRP, SetTy &S, |
0 |
| 9531 |
bool &ContainsUndef, bool ForSelf) { |
--- |
9531 |
bool &ContainsUndef, bool ForSelf) { |
--- |
| 9532 |
SmallVector Values; |
0 |
9532 |
SmallVector Values; |
0 |
| 9533 |
bool UsedAssumedInformation = false; |
0 |
9533 |
bool UsedAssumedInformation = false; |
0 |
| 9534 |
if (!A.getAssumedSimplifiedValues(IRP, *this, Values, AA::Interprocedural, |
0 |
9534 |
if (!A.getAssumedSimplifiedValues(IRP, *this, Values, AA::Interprocedural, |
0 |
| 9535 |
UsedAssumedInformation)) { |
--- |
9535 |
UsedAssumedInformation)) { |
--- |
| 9536 |
// Avoid recursion when the caller is computing constant values for this |
--- |
9536 |
// Avoid recursion when the caller is computing constant values for this |
--- |
| 9537 |
// IRP itself. |
--- |
9537 |
// IRP itself. |
--- |
| 9538 |
if (ForSelf) |
0 |
9538 |
if (ForSelf) |
0 |
| 9539 |
return false; |
0 |
9539 |
return false; |
0 |
| 9540 |
if (!IRP.getAssociatedType()->isIntegerTy()) |
0 |
9540 |
if (!IRP.getAssociatedType()->isIntegerTy()) |
0 |
| 9541 |
return false; |
0 |
9541 |
return false; |
0 |
| 9542 |
auto *PotentialValuesAA = A.getAAFor( |
0 |
9542 |
auto *PotentialValuesAA = A.getAAFor( |
0 |
| 9543 |
*this, IRP, DepClassTy::REQUIRED); |
--- |
9543 |
*this, IRP, DepClassTy::REQUIRED); |
--- |
| 9544 |
if (!PotentialValuesAA || !PotentialValuesAA->getState().isValidState()) |
0 |
9544 |
if (!PotentialValuesAA || !PotentialValuesAA->getState().isValidState()) |
0 |
| 9545 |
return false; |
0 |
9545 |
return false; |
0 |
| 9546 |
ContainsUndef = PotentialValuesAA->getState().undefIsContained(); |
0 |
9546 |
ContainsUndef = PotentialValuesAA->getState().undefIsContained(); |
0 |
| 9547 |
S = PotentialValuesAA->getState().getAssumedSet(); |
0 |
9547 |
S = PotentialValuesAA->getState().getAssumedSet(); |
0 |
| 9548 |
return true; |
0 |
9548 |
return true; |
0 |
| 9549 |
} |
--- |
9549 |
} |
--- |
| 9550 |
|
--- |
9550 |
|
--- |
| 9551 |
// Copy all the constant values, except UndefValue. ContainsUndef is true |
--- |
9551 |
// Copy all the constant values, except UndefValue. ContainsUndef is true |
--- |
| 9552 |
// iff Values contains only UndefValue instances. If there are other known |
--- |
9552 |
// iff Values contains only UndefValue instances. If there are other known |
--- |
| 9553 |
// constants, then UndefValue is dropped. |
--- |
9553 |
// constants, then UndefValue is dropped. |
--- |
| 9554 |
ContainsUndef = false; |
0 |
9554 |
ContainsUndef = false; |
0 |
| 9555 |
for (auto &It : Values) { |
0 |
9555 |
for (auto &It : Values) { |
0 |
| 9556 |
if (isa(It.getValue())) { |
0 |
9556 |
if (isa(It.getValue())) { |
0 |
| 9557 |
ContainsUndef = true; |
0 |
9557 |
ContainsUndef = true; |
0 |
| 9558 |
continue; |
0 |
9558 |
continue; |
0 |
| 9559 |
} |
--- |
9559 |
} |
--- |
| 9560 |
auto *CI = dyn_cast(It.getValue()); |
0 |
9560 |
auto *CI = dyn_cast(It.getValue()); |
0 |
| 9561 |
if (!CI) |
0 |
9561 |
if (!CI) |
0 |
| 9562 |
return false; |
0 |
9562 |
return false; |
0 |
| 9563 |
S.insert(CI->getValue()); |
0 |
9563 |
S.insert(CI->getValue()); |
0 |
| 9564 |
} |
--- |
9564 |
} |
--- |
| 9565 |
ContainsUndef &= S.empty(); |
0 |
9565 |
ContainsUndef &= S.empty(); |
0 |
| 9566 |
|
--- |
9566 |
|
--- |
| 9567 |
return true; |
0 |
9567 |
return true; |
0 |
| 9568 |
} |
0 |
9568 |
} |
0 |
| 9569 |
|
--- |
9569 |
|
--- |
| 9570 |
/// See AbstractAttribute::getAsStr(). |
--- |
9570 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 9571 |
const std::string getAsStr(Attributor *A) const override { |
0 |
9571 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 9572 |
std::string Str; |
0 |
9572 |
std::string Str; |
0 |
| 9573 |
llvm::raw_string_ostream OS(Str); |
0 |
9573 |
llvm::raw_string_ostream OS(Str); |
0 |
| 9574 |
OS << getState(); |
0 |
9574 |
OS << getState(); |
0 |
| 9575 |
return OS.str(); |
0 |
9575 |
return OS.str(); |
0 |
| 9576 |
} |
0 |
9576 |
} |
0 |
| 9577 |
|
--- |
9577 |
|
--- |
| 9578 |
/// See AbstractAttribute::updateImpl(...). |
--- |
9578 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 9579 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
9579 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 9580 |
return indicatePessimisticFixpoint(); |
0 |
9580 |
return indicatePessimisticFixpoint(); |
0 |
| 9581 |
} |
--- |
9581 |
} |
--- |
| 9582 |
}; |
--- |
9582 |
}; |
--- |
| 9583 |
|
--- |
9583 |
|
--- |
| 9584 |
struct AAPotentialConstantValuesArgument final |
--- |
9584 |
struct AAPotentialConstantValuesArgument final |
--- |
| 9585 |
: AAArgumentFromCallSiteArguments
| --- |
9585 |
: AAArgumentFromCallSiteArguments
| --- |
| |
| 9586 |
AAPotentialConstantValuesImpl, |
--- |
9586 |
AAPotentialConstantValuesImpl, |
--- |
| 9587 |
PotentialConstantIntValuesState> { |
--- |
9587 |
PotentialConstantIntValuesState> { |
--- |
| 9588 |
using Base = AAArgumentFromCallSiteArguments
| --- |
9588 |
using Base = AAArgumentFromCallSiteArguments
| --- |
| |
| 9589 |
AAPotentialConstantValuesImpl, |
--- |
9589 |
AAPotentialConstantValuesImpl, |
--- |
| 9590 |
PotentialConstantIntValuesState>; |
--- |
9590 |
PotentialConstantIntValuesState>; |
--- |
| 9591 |
AAPotentialConstantValuesArgument(const IRPosition &IRP, Attributor &A) |
0 |
9591 |
AAPotentialConstantValuesArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 9592 |
: Base(IRP, A) {} |
0 |
9592 |
: Base(IRP, A) {} |
0 |
| 9593 |
|
--- |
9593 |
|
--- |
| 9594 |
/// See AbstractAttribute::trackStatistics() |
--- |
9594 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9595 |
void trackStatistics() const override { |
0 |
9595 |
void trackStatistics() const override { |
0 |
| 9596 |
STATS_DECLTRACK_ARG_ATTR(potential_values) |
0 |
9596 |
STATS_DECLTRACK_ARG_ATTR(potential_values) |
0 |
| 9597 |
} |
0 |
9597 |
} |
0 |
| 9598 |
}; |
--- |
9598 |
}; |
--- |
| 9599 |
|
--- |
9599 |
|
--- |
| 9600 |
struct AAPotentialConstantValuesReturned |
--- |
9600 |
struct AAPotentialConstantValuesReturned |
--- |
| 9601 |
: AAReturnedFromReturnedValues
| --- |
9601 |
: AAReturnedFromReturnedValues
| --- |
| |
| 9602 |
AAPotentialConstantValuesImpl> { |
--- |
9602 |
AAPotentialConstantValuesImpl> { |
--- |
| 9603 |
using Base = AAReturnedFromReturnedValues
| --- |
9603 |
using Base = AAReturnedFromReturnedValues
| --- |
| |
| 9604 |
AAPotentialConstantValuesImpl>; |
--- |
9604 |
AAPotentialConstantValuesImpl>; |
--- |
| 9605 |
AAPotentialConstantValuesReturned(const IRPosition &IRP, Attributor &A) |
0 |
9605 |
AAPotentialConstantValuesReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 9606 |
: Base(IRP, A) {} |
0 |
9606 |
: Base(IRP, A) {} |
0 |
| 9607 |
|
--- |
9607 |
|
--- |
| 9608 |
void initialize(Attributor &A) override { |
0 |
9608 |
void initialize(Attributor &A) override { |
0 |
| 9609 |
if (!A.isFunctionIPOAmendable(*getAssociatedFunction())) |
0 |
9609 |
if (!A.isFunctionIPOAmendable(*getAssociatedFunction())) |
0 |
| 9610 |
indicatePessimisticFixpoint(); |
0 |
9610 |
indicatePessimisticFixpoint(); |
0 |
| 9611 |
Base::initialize(A); |
0 |
9611 |
Base::initialize(A); |
0 |
| 9612 |
} |
0 |
9612 |
} |
0 |
| 9613 |
|
--- |
9613 |
|
--- |
| 9614 |
/// See AbstractAttribute::trackStatistics() |
--- |
9614 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9615 |
void trackStatistics() const override { |
0 |
9615 |
void trackStatistics() const override { |
0 |
| 9616 |
STATS_DECLTRACK_FNRET_ATTR(potential_values) |
0 |
9616 |
STATS_DECLTRACK_FNRET_ATTR(potential_values) |
0 |
| 9617 |
} |
0 |
9617 |
} |
0 |
| 9618 |
}; |
--- |
9618 |
}; |
--- |
| 9619 |
|
--- |
9619 |
|
--- |
| 9620 |
struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl { |
--- |
9620 |
struct AAPotentialConstantValuesFloating : AAPotentialConstantValuesImpl { |
--- |
| 9621 |
AAPotentialConstantValuesFloating(const IRPosition &IRP, Attributor &A) |
0 |
9621 |
AAPotentialConstantValuesFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 9622 |
: AAPotentialConstantValuesImpl(IRP, A) {} |
0 |
9622 |
: AAPotentialConstantValuesImpl(IRP, A) {} |
0 |
| 9623 |
|
--- |
9623 |
|
--- |
| 9624 |
/// See AbstractAttribute::initialize(..). |
--- |
9624 |
/// See AbstractAttribute::initialize(..). |
--- |
| 9625 |
void initialize(Attributor &A) override { |
0 |
9625 |
void initialize(Attributor &A) override { |
0 |
| 9626 |
AAPotentialConstantValuesImpl::initialize(A); |
0 |
9626 |
AAPotentialConstantValuesImpl::initialize(A); |
0 |
| 9627 |
if (isAtFixpoint()) |
0 |
9627 |
if (isAtFixpoint()) |
0 |
| 9628 |
return; |
0 |
9628 |
return; |
0 |
| 9629 |
|
--- |
9629 |
|
--- |
| 9630 |
Value &V = getAssociatedValue(); |
0 |
9630 |
Value &V = getAssociatedValue(); |
0 |
| 9631 |
|
--- |
9631 |
|
--- |
| 9632 |
if (auto *C = dyn_cast(&V)) { |
0 |
9632 |
if (auto *C = dyn_cast(&V)) { |
0 |
| 9633 |
unionAssumed(C->getValue()); |
0 |
9633 |
unionAssumed(C->getValue()); |
0 |
| 9634 |
indicateOptimisticFixpoint(); |
0 |
9634 |
indicateOptimisticFixpoint(); |
0 |
| 9635 |
return; |
0 |
9635 |
return; |
0 |
| 9636 |
} |
--- |
9636 |
} |
--- |
| 9637 |
|
--- |
9637 |
|
--- |
| 9638 |
if (isa(&V)) { |
0 |
9638 |
if (isa(&V)) { |
0 |
| 9639 |
unionAssumedWithUndef(); |
0 |
9639 |
unionAssumedWithUndef(); |
0 |
| 9640 |
indicateOptimisticFixpoint(); |
0 |
9640 |
indicateOptimisticFixpoint(); |
0 |
| 9641 |
return; |
0 |
9641 |
return; |
0 |
| 9642 |
} |
--- |
9642 |
} |
--- |
| 9643 |
|
--- |
9643 |
|
--- |
| 9644 |
if (isa(&V) || isa(&V) || isa(&V)) |
0 |
9644 |
if (isa(&V) || isa(&V) || isa(&V)) |
0 |
| 9645 |
return; |
0 |
9645 |
return; |
0 |
| 9646 |
|
--- |
9646 |
|
--- |
| 9647 |
if (isa(V) || isa(V) || isa(V)) |
0 |
9647 |
if (isa(V) || isa(V) || isa(V)) |
0 |
| 9648 |
return; |
0 |
9648 |
return; |
0 |
| 9649 |
|
--- |
9649 |
|
--- |
| 9650 |
indicatePessimisticFixpoint(); |
0 |
9650 |
indicatePessimisticFixpoint(); |
0 |
| 9651 |
|
--- |
9651 |
|
--- |
| 9652 |
LLVM_DEBUG(dbgs() << "[AAPotentialConstantValues] We give up: " |
0 |
9652 |
LLVM_DEBUG(dbgs() << "[AAPotentialConstantValues] We give up: " |
0 |
| 9653 |
<< getAssociatedValue() << "\n"); |
--- |
9653 |
<< getAssociatedValue() << "\n"); |
--- |
| 9654 |
} |
--- |
9654 |
} |
--- |
| 9655 |
|
--- |
9655 |
|
--- |
| 9656 |
static bool calculateICmpInst(const ICmpInst *ICI, const APInt &LHS, |
0 |
9656 |
static bool calculateICmpInst(const ICmpInst *ICI, const APInt &LHS, |
0 |
| 9657 |
const APInt &RHS) { |
--- |
9657 |
const APInt &RHS) { |
--- |
| 9658 |
return ICmpInst::compare(LHS, RHS, ICI->getPredicate()); |
0 |
9658 |
return ICmpInst::compare(LHS, RHS, ICI->getPredicate()); |
0 |
| 9659 |
} |
--- |
9659 |
} |
--- |
| 9660 |
|
--- |
9660 |
|
--- |
| 9661 |
static APInt calculateCastInst(const CastInst *CI, const APInt &Src, |
0 |
9661 |
static APInt calculateCastInst(const CastInst *CI, const APInt &Src, |
0 |
| 9662 |
uint32_t ResultBitWidth) { |
--- |
9662 |
uint32_t ResultBitWidth) { |
--- |
| 9663 |
Instruction::CastOps CastOp = CI->getOpcode(); |
0 |
9663 |
Instruction::CastOps CastOp = CI->getOpcode(); |
0 |
| 9664 |
switch (CastOp) { |
0 |
9664 |
switch (CastOp) { |
0 |
| 9665 |
default: |
0 |
9665 |
default: |
0 |
| 9666 |
llvm_unreachable("unsupported or not integer cast"); |
0 |
9666 |
llvm_unreachable("unsupported or not integer cast"); |
0 |
| 9667 |
case Instruction::Trunc: |
0 |
9667 |
case Instruction::Trunc: |
0 |
| 9668 |
return Src.trunc(ResultBitWidth); |
0 |
9668 |
return Src.trunc(ResultBitWidth); |
0 |
| 9669 |
case Instruction::SExt: |
0 |
9669 |
case Instruction::SExt: |
0 |
| 9670 |
return Src.sext(ResultBitWidth); |
0 |
9670 |
return Src.sext(ResultBitWidth); |
0 |
| 9671 |
case Instruction::ZExt: |
0 |
9671 |
case Instruction::ZExt: |
0 |
| 9672 |
return Src.zext(ResultBitWidth); |
0 |
9672 |
return Src.zext(ResultBitWidth); |
0 |
| 9673 |
case Instruction::BitCast: |
0 |
9673 |
case Instruction::BitCast: |
0 |
| 9674 |
return Src; |
0 |
9674 |
return Src; |
0 |
| 9675 |
} |
--- |
9675 |
} |
--- |
| 9676 |
} |
--- |
9676 |
} |
--- |
| 9677 |
|
--- |
9677 |
|
--- |
| 9678 |
static APInt calculateBinaryOperator(const BinaryOperator *BinOp, |
0 |
9678 |
static APInt calculateBinaryOperator(const BinaryOperator *BinOp, |
0 |
| 9679 |
const APInt &LHS, const APInt &RHS, |
--- |
9679 |
const APInt &LHS, const APInt &RHS, |
--- |
| 9680 |
bool &SkipOperation, bool &Unsupported) { |
--- |
9680 |
bool &SkipOperation, bool &Unsupported) { |
--- |
| 9681 |
Instruction::BinaryOps BinOpcode = BinOp->getOpcode(); |
0 |
9681 |
Instruction::BinaryOps BinOpcode = BinOp->getOpcode(); |
0 |
| 9682 |
// Unsupported is set to true when the binary operator is not supported. |
--- |
9682 |
// Unsupported is set to true when the binary operator is not supported. |
--- |
| 9683 |
// SkipOperation is set to true when UB occur with the given operand pair |
--- |
9683 |
// SkipOperation is set to true when UB occur with the given operand pair |
--- |
| 9684 |
// (LHS, RHS). |
--- |
9684 |
// (LHS, RHS). |
--- |
| 9685 |
// TODO: we should look at nsw and nuw keywords to handle operations |
--- |
9685 |
// TODO: we should look at nsw and nuw keywords to handle operations |
--- |
| 9686 |
// that create poison or undef value. |
--- |
9686 |
// that create poison or undef value. |
--- |
| 9687 |
switch (BinOpcode) { |
0 |
9687 |
switch (BinOpcode) { |
0 |
| 9688 |
default: |
0 |
9688 |
default: |
0 |
| 9689 |
Unsupported = true; |
0 |
9689 |
Unsupported = true; |
0 |
| 9690 |
return LHS; |
0 |
9690 |
return LHS; |
0 |
| 9691 |
case Instruction::Add: |
0 |
9691 |
case Instruction::Add: |
0 |
| 9692 |
return LHS + RHS; |
0 |
9692 |
return LHS + RHS; |
0 |
| 9693 |
case Instruction::Sub: |
0 |
9693 |
case Instruction::Sub: |
0 |
| 9694 |
return LHS - RHS; |
0 |
9694 |
return LHS - RHS; |
0 |
| 9695 |
case Instruction::Mul: |
0 |
9695 |
case Instruction::Mul: |
0 |
| 9696 |
return LHS * RHS; |
0 |
9696 |
return LHS * RHS; |
0 |
| 9697 |
case Instruction::UDiv: |
0 |
9697 |
case Instruction::UDiv: |
0 |
| 9698 |
if (RHS.isZero()) { |
0 |
9698 |
if (RHS.isZero()) { |
0 |
| 9699 |
SkipOperation = true; |
0 |
9699 |
SkipOperation = true; |
0 |
| 9700 |
return LHS; |
0 |
9700 |
return LHS; |
0 |
| 9701 |
} |
--- |
9701 |
} |
--- |
| 9702 |
return LHS.udiv(RHS); |
0 |
9702 |
return LHS.udiv(RHS); |
0 |
| 9703 |
case Instruction::SDiv: |
0 |
9703 |
case Instruction::SDiv: |
0 |
| 9704 |
if (RHS.isZero()) { |
0 |
9704 |
if (RHS.isZero()) { |
0 |
| 9705 |
SkipOperation = true; |
0 |
9705 |
SkipOperation = true; |
0 |
| 9706 |
return LHS; |
0 |
9706 |
return LHS; |
0 |
| 9707 |
} |
--- |
9707 |
} |
--- |
| 9708 |
return LHS.sdiv(RHS); |
0 |
9708 |
return LHS.sdiv(RHS); |
0 |
| 9709 |
case Instruction::URem: |
0 |
9709 |
case Instruction::URem: |
0 |
| 9710 |
if (RHS.isZero()) { |
0 |
9710 |
if (RHS.isZero()) { |
0 |
| 9711 |
SkipOperation = true; |
0 |
9711 |
SkipOperation = true; |
0 |
| 9712 |
return LHS; |
0 |
9712 |
return LHS; |
0 |
| 9713 |
} |
--- |
9713 |
} |
--- |
| 9714 |
return LHS.urem(RHS); |
0 |
9714 |
return LHS.urem(RHS); |
0 |
| 9715 |
case Instruction::SRem: |
0 |
9715 |
case Instruction::SRem: |
0 |
| 9716 |
if (RHS.isZero()) { |
0 |
9716 |
if (RHS.isZero()) { |
0 |
| 9717 |
SkipOperation = true; |
0 |
9717 |
SkipOperation = true; |
0 |
| 9718 |
return LHS; |
0 |
9718 |
return LHS; |
0 |
| 9719 |
} |
--- |
9719 |
} |
--- |
| 9720 |
return LHS.srem(RHS); |
0 |
9720 |
return LHS.srem(RHS); |
0 |
| 9721 |
case Instruction::Shl: |
0 |
9721 |
case Instruction::Shl: |
0 |
| 9722 |
return LHS.shl(RHS); |
0 |
9722 |
return LHS.shl(RHS); |
0 |
| 9723 |
case Instruction::LShr: |
0 |
9723 |
case Instruction::LShr: |
0 |
| 9724 |
return LHS.lshr(RHS); |
0 |
9724 |
return LHS.lshr(RHS); |
0 |
| 9725 |
case Instruction::AShr: |
0 |
9725 |
case Instruction::AShr: |
0 |
| 9726 |
return LHS.ashr(RHS); |
0 |
9726 |
return LHS.ashr(RHS); |
0 |
| 9727 |
case Instruction::And: |
0 |
9727 |
case Instruction::And: |
0 |
| 9728 |
return LHS & RHS; |
0 |
9728 |
return LHS & RHS; |
0 |
| 9729 |
case Instruction::Or: |
0 |
9729 |
case Instruction::Or: |
0 |
| 9730 |
return LHS | RHS; |
0 |
9730 |
return LHS | RHS; |
0 |
| 9731 |
case Instruction::Xor: |
0 |
9731 |
case Instruction::Xor: |
0 |
| 9732 |
return LHS ^ RHS; |
0 |
9732 |
return LHS ^ RHS; |
0 |
| 9733 |
} |
--- |
9733 |
} |
--- |
| 9734 |
} |
--- |
9734 |
} |
--- |
| 9735 |
|
--- |
9735 |
|
--- |
| 9736 |
bool calculateBinaryOperatorAndTakeUnion(const BinaryOperator *BinOp, |
0 |
9736 |
bool calculateBinaryOperatorAndTakeUnion(const BinaryOperator *BinOp, |
0 |
| 9737 |
const APInt &LHS, const APInt &RHS) { |
--- |
9737 |
const APInt &LHS, const APInt &RHS) { |
--- |
| 9738 |
bool SkipOperation = false; |
0 |
9738 |
bool SkipOperation = false; |
0 |
| 9739 |
bool Unsupported = false; |
0 |
9739 |
bool Unsupported = false; |
0 |
| 9740 |
APInt Result = |
--- |
9740 |
APInt Result = |
--- |
| 9741 |
calculateBinaryOperator(BinOp, LHS, RHS, SkipOperation, Unsupported); |
0 |
9741 |
calculateBinaryOperator(BinOp, LHS, RHS, SkipOperation, Unsupported); |
0 |
| 9742 |
if (Unsupported) |
0 |
9742 |
if (Unsupported) |
0 |
| 9743 |
return false; |
0 |
9743 |
return false; |
0 |
| 9744 |
// If SkipOperation is true, we can ignore this operand pair (L, R). |
--- |
9744 |
// If SkipOperation is true, we can ignore this operand pair (L, R). |
--- |
| 9745 |
if (!SkipOperation) |
0 |
9745 |
if (!SkipOperation) |
0 |
| 9746 |
unionAssumed(Result); |
0 |
9746 |
unionAssumed(Result); |
0 |
| 9747 |
return isValidState(); |
0 |
9747 |
return isValidState(); |
0 |
| 9748 |
} |
0 |
9748 |
} |
0 |
| 9749 |
|
--- |
9749 |
|
--- |
| 9750 |
ChangeStatus updateWithICmpInst(Attributor &A, ICmpInst *ICI) { |
0 |
9750 |
ChangeStatus updateWithICmpInst(Attributor &A, ICmpInst *ICI) { |
0 |
| 9751 |
auto AssumedBefore = getAssumed(); |
0 |
9751 |
auto AssumedBefore = getAssumed(); |
0 |
| 9752 |
Value *LHS = ICI->getOperand(0); |
0 |
9752 |
Value *LHS = ICI->getOperand(0); |
0 |
| 9753 |
Value *RHS = ICI->getOperand(1); |
0 |
9753 |
Value *RHS = ICI->getOperand(1); |
0 |
| 9754 |
|
--- |
9754 |
|
--- |
| 9755 |
bool LHSContainsUndef = false, RHSContainsUndef = false; |
0 |
9755 |
bool LHSContainsUndef = false, RHSContainsUndef = false; |
0 |
| 9756 |
SetTy LHSAAPVS, RHSAAPVS; |
0 |
9756 |
SetTy LHSAAPVS, RHSAAPVS; |
0 |
| 9757 |
if (!fillSetWithConstantValues(A, IRPosition::value(*LHS), LHSAAPVS, |
0 |
9757 |
if (!fillSetWithConstantValues(A, IRPosition::value(*LHS), LHSAAPVS, |
0 |
| 9758 |
LHSContainsUndef, /* ForSelf */ false) || |
0 |
9758 |
LHSContainsUndef, /* ForSelf */ false) || |
0 |
| 9759 |
!fillSetWithConstantValues(A, IRPosition::value(*RHS), RHSAAPVS, |
0 |
9759 |
!fillSetWithConstantValues(A, IRPosition::value(*RHS), RHSAAPVS, |
0 |
| 9760 |
RHSContainsUndef, /* ForSelf */ false)) |
--- |
9760 |
RHSContainsUndef, /* ForSelf */ false)) |
--- |
| 9761 |
return indicatePessimisticFixpoint(); |
0 |
9761 |
return indicatePessimisticFixpoint(); |
0 |
| 9762 |
|
--- |
9762 |
|
--- |
| 9763 |
// TODO: make use of undef flag to limit potential values aggressively. |
--- |
9763 |
// TODO: make use of undef flag to limit potential values aggressively. |
--- |
| 9764 |
bool MaybeTrue = false, MaybeFalse = false; |
0 |
9764 |
bool MaybeTrue = false, MaybeFalse = false; |
0 |
| 9765 |
const APInt Zero(RHS->getType()->getIntegerBitWidth(), 0); |
0 |
9765 |
const APInt Zero(RHS->getType()->getIntegerBitWidth(), 0); |
0 |
| 9766 |
if (LHSContainsUndef && RHSContainsUndef) { |
0 |
9766 |
if (LHSContainsUndef && RHSContainsUndef) { |
0 |
| 9767 |
// The result of any comparison between undefs can be soundly replaced |
--- |
9767 |
// The result of any comparison between undefs can be soundly replaced |
--- |
| 9768 |
// with undef. |
--- |
9768 |
// with undef. |
--- |
| 9769 |
unionAssumedWithUndef(); |
0 |
9769 |
unionAssumedWithUndef(); |
0 |
| 9770 |
} else if (LHSContainsUndef) { |
0 |
9770 |
} else if (LHSContainsUndef) { |
0 |
| 9771 |
for (const APInt &R : RHSAAPVS) { |
0 |
9771 |
for (const APInt &R : RHSAAPVS) { |
0 |
| 9772 |
bool CmpResult = calculateICmpInst(ICI, Zero, R); |
0 |
9772 |
bool CmpResult = calculateICmpInst(ICI, Zero, R); |
0 |
| 9773 |
MaybeTrue |= CmpResult; |
0 |
9773 |
MaybeTrue |= CmpResult; |
0 |
| 9774 |
MaybeFalse |= !CmpResult; |
0 |
9774 |
MaybeFalse |= !CmpResult; |
0 |
| 9775 |
if (MaybeTrue & MaybeFalse) |
0 |
9775 |
if (MaybeTrue & MaybeFalse) |
0 |
| 9776 |
return indicatePessimisticFixpoint(); |
0 |
9776 |
return indicatePessimisticFixpoint(); |
0 |
| 9777 |
} |
--- |
9777 |
} |
--- |
| 9778 |
} else if (RHSContainsUndef) { |
0 |
9778 |
} else if (RHSContainsUndef) { |
0 |
| 9779 |
for (const APInt &L : LHSAAPVS) { |
0 |
9779 |
for (const APInt &L : LHSAAPVS) { |
0 |
| 9780 |
bool CmpResult = calculateICmpInst(ICI, L, Zero); |
0 |
9780 |
bool CmpResult = calculateICmpInst(ICI, L, Zero); |
0 |
| 9781 |
MaybeTrue |= CmpResult; |
0 |
9781 |
MaybeTrue |= CmpResult; |
0 |
| 9782 |
MaybeFalse |= !CmpResult; |
0 |
9782 |
MaybeFalse |= !CmpResult; |
0 |
| 9783 |
if (MaybeTrue & MaybeFalse) |
0 |
9783 |
if (MaybeTrue & MaybeFalse) |
0 |
| 9784 |
return indicatePessimisticFixpoint(); |
0 |
9784 |
return indicatePessimisticFixpoint(); |
0 |
| 9785 |
} |
--- |
9785 |
} |
--- |
| 9786 |
} else { |
--- |
9786 |
} else { |
--- |
| 9787 |
for (const APInt &L : LHSAAPVS) { |
0 |
9787 |
for (const APInt &L : LHSAAPVS) { |
0 |
| 9788 |
for (const APInt &R : RHSAAPVS) { |
0 |
9788 |
for (const APInt &R : RHSAAPVS) { |
0 |
| 9789 |
bool CmpResult = calculateICmpInst(ICI, L, R); |
0 |
9789 |
bool CmpResult = calculateICmpInst(ICI, L, R); |
0 |
| 9790 |
MaybeTrue |= CmpResult; |
0 |
9790 |
MaybeTrue |= CmpResult; |
0 |
| 9791 |
MaybeFalse |= !CmpResult; |
0 |
9791 |
MaybeFalse |= !CmpResult; |
0 |
| 9792 |
if (MaybeTrue & MaybeFalse) |
0 |
9792 |
if (MaybeTrue & MaybeFalse) |
0 |
| 9793 |
return indicatePessimisticFixpoint(); |
0 |
9793 |
return indicatePessimisticFixpoint(); |
0 |
| 9794 |
} |
--- |
9794 |
} |
--- |
| 9795 |
} |
--- |
9795 |
} |
--- |
| 9796 |
} |
--- |
9796 |
} |
--- |
| 9797 |
if (MaybeTrue) |
0 |
9797 |
if (MaybeTrue) |
0 |
| 9798 |
unionAssumed(APInt(/* numBits */ 1, /* val */ 1)); |
0 |
9798 |
unionAssumed(APInt(/* numBits */ 1, /* val */ 1)); |
0 |
| 9799 |
if (MaybeFalse) |
0 |
9799 |
if (MaybeFalse) |
0 |
| 9800 |
unionAssumed(APInt(/* numBits */ 1, /* val */ 0)); |
0 |
9800 |
unionAssumed(APInt(/* numBits */ 1, /* val */ 0)); |
0 |
| 9801 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
9801 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
| 9802 |
: ChangeStatus::CHANGED; |
0 |
9802 |
: ChangeStatus::CHANGED; |
0 |
| 9803 |
} |
0 |
9803 |
} |
0 |
| 9804 |
|
--- |
9804 |
|
--- |
| 9805 |
ChangeStatus updateWithSelectInst(Attributor &A, SelectInst *SI) { |
0 |
9805 |
ChangeStatus updateWithSelectInst(Attributor &A, SelectInst *SI) { |
0 |
| 9806 |
auto AssumedBefore = getAssumed(); |
0 |
9806 |
auto AssumedBefore = getAssumed(); |
0 |
| 9807 |
Value *LHS = SI->getTrueValue(); |
0 |
9807 |
Value *LHS = SI->getTrueValue(); |
0 |
| 9808 |
Value *RHS = SI->getFalseValue(); |
0 |
9808 |
Value *RHS = SI->getFalseValue(); |
0 |
| 9809 |
|
--- |
9809 |
|
--- |
| 9810 |
bool UsedAssumedInformation = false; |
0 |
9810 |
bool UsedAssumedInformation = false; |
0 |
| 9811 |
std::optional C = A.getAssumedConstant( |
0 |
9811 |
std::optional C = A.getAssumedConstant( |
0 |
| 9812 |
*SI->getCondition(), *this, UsedAssumedInformation); |
0 |
9812 |
*SI->getCondition(), *this, UsedAssumedInformation); |
0 |
| 9813 |
|
--- |
9813 |
|
--- |
| 9814 |
// Check if we only need one operand. |
--- |
9814 |
// Check if we only need one operand. |
--- |
| 9815 |
bool OnlyLeft = false, OnlyRight = false; |
0 |
9815 |
bool OnlyLeft = false, OnlyRight = false; |
0 |
| 9816 |
if (C && *C && (*C)->isOneValue()) |
0 |
9816 |
if (C && *C && (*C)->isOneValue()) |
0 |
| 9817 |
OnlyLeft = true; |
0 |
9817 |
OnlyLeft = true; |
0 |
| 9818 |
else if (C && *C && (*C)->isZeroValue()) |
0 |
9818 |
else if (C && *C && (*C)->isZeroValue()) |
0 |
| 9819 |
OnlyRight = true; |
0 |
9819 |
OnlyRight = true; |
0 |
| 9820 |
|
--- |
9820 |
|
--- |
| 9821 |
bool LHSContainsUndef = false, RHSContainsUndef = false; |
0 |
9821 |
bool LHSContainsUndef = false, RHSContainsUndef = false; |
0 |
| 9822 |
SetTy LHSAAPVS, RHSAAPVS; |
0 |
9822 |
SetTy LHSAAPVS, RHSAAPVS; |
0 |
| 9823 |
if (!OnlyRight && |
0 |
9823 |
if (!OnlyRight && |
0 |
| 9824 |
!fillSetWithConstantValues(A, IRPosition::value(*LHS), LHSAAPVS, |
0 |
9824 |
!fillSetWithConstantValues(A, IRPosition::value(*LHS), LHSAAPVS, |
0 |
| 9825 |
LHSContainsUndef, /* ForSelf */ false)) |
--- |
9825 |
LHSContainsUndef, /* ForSelf */ false)) |
--- |
| 9826 |
return indicatePessimisticFixpoint(); |
0 |
9826 |
return indicatePessimisticFixpoint(); |
0 |
| 9827 |
|
--- |
9827 |
|
--- |
| 9828 |
if (!OnlyLeft && |
0 |
9828 |
if (!OnlyLeft && |
0 |
| 9829 |
!fillSetWithConstantValues(A, IRPosition::value(*RHS), RHSAAPVS, |
0 |
9829 |
!fillSetWithConstantValues(A, IRPosition::value(*RHS), RHSAAPVS, |
0 |
| 9830 |
RHSContainsUndef, /* ForSelf */ false)) |
--- |
9830 |
RHSContainsUndef, /* ForSelf */ false)) |
--- |
| 9831 |
return indicatePessimisticFixpoint(); |
0 |
9831 |
return indicatePessimisticFixpoint(); |
0 |
| 9832 |
|
--- |
9832 |
|
--- |
| 9833 |
if (OnlyLeft || OnlyRight) { |
0 |
9833 |
if (OnlyLeft || OnlyRight) { |
0 |
| 9834 |
// select (true/false), lhs, rhs |
--- |
9834 |
// select (true/false), lhs, rhs |
--- |
| 9835 |
auto *OpAA = OnlyLeft ? &LHSAAPVS : &RHSAAPVS; |
0 |
9835 |
auto *OpAA = OnlyLeft ? &LHSAAPVS : &RHSAAPVS; |
0 |
| 9836 |
auto Undef = OnlyLeft ? LHSContainsUndef : RHSContainsUndef; |
0 |
9836 |
auto Undef = OnlyLeft ? LHSContainsUndef : RHSContainsUndef; |
0 |
| 9837 |
|
--- |
9837 |
|
--- |
| 9838 |
if (Undef) |
0 |
9838 |
if (Undef) |
0 |
| 9839 |
unionAssumedWithUndef(); |
0 |
9839 |
unionAssumedWithUndef(); |
0 |
| 9840 |
else { |
--- |
9840 |
else { |
--- |
| 9841 |
for (const auto &It : *OpAA) |
0 |
9841 |
for (const auto &It : *OpAA) |
0 |
| 9842 |
unionAssumed(It); |
0 |
9842 |
unionAssumed(It); |
0 |
| 9843 |
} |
--- |
9843 |
} |
--- |
| 9844 |
|
--- |
9844 |
|
--- |
| 9845 |
} else if (LHSContainsUndef && RHSContainsUndef) { |
0 |
9845 |
} else if (LHSContainsUndef && RHSContainsUndef) { |
0 |
| 9846 |
// select i1 *, undef , undef => undef |
--- |
9846 |
// select i1 *, undef , undef => undef |
--- |
| 9847 |
unionAssumedWithUndef(); |
0 |
9847 |
unionAssumedWithUndef(); |
0 |
| 9848 |
} else { |
--- |
9848 |
} else { |
--- |
| 9849 |
for (const auto &It : LHSAAPVS) |
0 |
9849 |
for (const auto &It : LHSAAPVS) |
0 |
| 9850 |
unionAssumed(It); |
0 |
9850 |
unionAssumed(It); |
0 |
| 9851 |
for (const auto &It : RHSAAPVS) |
0 |
9851 |
for (const auto &It : RHSAAPVS) |
0 |
| 9852 |
unionAssumed(It); |
0 |
9852 |
unionAssumed(It); |
0 |
| 9853 |
} |
--- |
9853 |
} |
--- |
| 9854 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
9854 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
| 9855 |
: ChangeStatus::CHANGED; |
0 |
9855 |
: ChangeStatus::CHANGED; |
0 |
| 9856 |
} |
0 |
9856 |
} |
0 |
| 9857 |
|
--- |
9857 |
|
--- |
| 9858 |
ChangeStatus updateWithCastInst(Attributor &A, CastInst *CI) { |
0 |
9858 |
ChangeStatus updateWithCastInst(Attributor &A, CastInst *CI) { |
0 |
| 9859 |
auto AssumedBefore = getAssumed(); |
0 |
9859 |
auto AssumedBefore = getAssumed(); |
0 |
| 9860 |
if (!CI->isIntegerCast()) |
0 |
9860 |
if (!CI->isIntegerCast()) |
0 |
| 9861 |
return indicatePessimisticFixpoint(); |
0 |
9861 |
return indicatePessimisticFixpoint(); |
0 |
| 9862 |
assert(CI->getNumOperands() == 1 && "Expected cast to be unary!"); |
0 |
9862 |
assert(CI->getNumOperands() == 1 && "Expected cast to be unary!"); |
0 |
| 9863 |
uint32_t ResultBitWidth = CI->getDestTy()->getIntegerBitWidth(); |
0 |
9863 |
uint32_t ResultBitWidth = CI->getDestTy()->getIntegerBitWidth(); |
0 |
| 9864 |
Value *Src = CI->getOperand(0); |
0 |
9864 |
Value *Src = CI->getOperand(0); |
0 |
| 9865 |
|
--- |
9865 |
|
--- |
| 9866 |
bool SrcContainsUndef = false; |
0 |
9866 |
bool SrcContainsUndef = false; |
0 |
| 9867 |
SetTy SrcPVS; |
0 |
9867 |
SetTy SrcPVS; |
0 |
| 9868 |
if (!fillSetWithConstantValues(A, IRPosition::value(*Src), SrcPVS, |
0 |
9868 |
if (!fillSetWithConstantValues(A, IRPosition::value(*Src), SrcPVS, |
0 |
| 9869 |
SrcContainsUndef, /* ForSelf */ false)) |
--- |
9869 |
SrcContainsUndef, /* ForSelf */ false)) |
--- |
| 9870 |
return indicatePessimisticFixpoint(); |
0 |
9870 |
return indicatePessimisticFixpoint(); |
0 |
| 9871 |
|
--- |
9871 |
|
--- |
| 9872 |
if (SrcContainsUndef) |
0 |
9872 |
if (SrcContainsUndef) |
0 |
| 9873 |
unionAssumedWithUndef(); |
0 |
9873 |
unionAssumedWithUndef(); |
0 |
| 9874 |
else { |
--- |
9874 |
else { |
--- |
| 9875 |
for (const APInt &S : SrcPVS) { |
0 |
9875 |
for (const APInt &S : SrcPVS) { |
0 |
| 9876 |
APInt T = calculateCastInst(CI, S, ResultBitWidth); |
0 |
9876 |
APInt T = calculateCastInst(CI, S, ResultBitWidth); |
0 |
| 9877 |
unionAssumed(T); |
0 |
9877 |
unionAssumed(T); |
0 |
| 9878 |
} |
0 |
9878 |
} |
0 |
| 9879 |
} |
--- |
9879 |
} |
--- |
| 9880 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
9880 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
| 9881 |
: ChangeStatus::CHANGED; |
0 |
9881 |
: ChangeStatus::CHANGED; |
0 |
| 9882 |
} |
0 |
9882 |
} |
0 |
| 9883 |
|
--- |
9883 |
|
--- |
| 9884 |
ChangeStatus updateWithBinaryOperator(Attributor &A, BinaryOperator *BinOp) { |
0 |
9884 |
ChangeStatus updateWithBinaryOperator(Attributor &A, BinaryOperator *BinOp) { |
0 |
| 9885 |
auto AssumedBefore = getAssumed(); |
0 |
9885 |
auto AssumedBefore = getAssumed(); |
0 |
| 9886 |
Value *LHS = BinOp->getOperand(0); |
0 |
9886 |
Value *LHS = BinOp->getOperand(0); |
0 |
| 9887 |
Value *RHS = BinOp->getOperand(1); |
0 |
9887 |
Value *RHS = BinOp->getOperand(1); |
0 |
| 9888 |
|
--- |
9888 |
|
--- |
| 9889 |
bool LHSContainsUndef = false, RHSContainsUndef = false; |
0 |
9889 |
bool LHSContainsUndef = false, RHSContainsUndef = false; |
0 |
| 9890 |
SetTy LHSAAPVS, RHSAAPVS; |
0 |
9890 |
SetTy LHSAAPVS, RHSAAPVS; |
0 |
| 9891 |
if (!fillSetWithConstantValues(A, IRPosition::value(*LHS), LHSAAPVS, |
0 |
9891 |
if (!fillSetWithConstantValues(A, IRPosition::value(*LHS), LHSAAPVS, |
0 |
| 9892 |
LHSContainsUndef, /* ForSelf */ false) || |
0 |
9892 |
LHSContainsUndef, /* ForSelf */ false) || |
0 |
| 9893 |
!fillSetWithConstantValues(A, IRPosition::value(*RHS), RHSAAPVS, |
0 |
9893 |
!fillSetWithConstantValues(A, IRPosition::value(*RHS), RHSAAPVS, |
0 |
| 9894 |
RHSContainsUndef, /* ForSelf */ false)) |
--- |
9894 |
RHSContainsUndef, /* ForSelf */ false)) |
--- |
| 9895 |
return indicatePessimisticFixpoint(); |
0 |
9895 |
return indicatePessimisticFixpoint(); |
0 |
| 9896 |
|
--- |
9896 |
|
--- |
| 9897 |
const APInt Zero = APInt(LHS->getType()->getIntegerBitWidth(), 0); |
0 |
9897 |
const APInt Zero = APInt(LHS->getType()->getIntegerBitWidth(), 0); |
0 |
| 9898 |
|
--- |
9898 |
|
--- |
| 9899 |
// TODO: make use of undef flag to limit potential values aggressively. |
--- |
9899 |
// TODO: make use of undef flag to limit potential values aggressively. |
--- |
| 9900 |
if (LHSContainsUndef && RHSContainsUndef) { |
0 |
9900 |
if (LHSContainsUndef && RHSContainsUndef) { |
0 |
| 9901 |
if (!calculateBinaryOperatorAndTakeUnion(BinOp, Zero, Zero)) |
0 |
9901 |
if (!calculateBinaryOperatorAndTakeUnion(BinOp, Zero, Zero)) |
0 |
| 9902 |
return indicatePessimisticFixpoint(); |
0 |
9902 |
return indicatePessimisticFixpoint(); |
0 |
| 9903 |
} else if (LHSContainsUndef) { |
0 |
9903 |
} else if (LHSContainsUndef) { |
0 |
| 9904 |
for (const APInt &R : RHSAAPVS) { |
0 |
9904 |
for (const APInt &R : RHSAAPVS) { |
0 |
| 9905 |
if (!calculateBinaryOperatorAndTakeUnion(BinOp, Zero, R)) |
0 |
9905 |
if (!calculateBinaryOperatorAndTakeUnion(BinOp, Zero, R)) |
0 |
| 9906 |
return indicatePessimisticFixpoint(); |
0 |
9906 |
return indicatePessimisticFixpoint(); |
0 |
| 9907 |
} |
--- |
9907 |
} |
--- |
| 9908 |
} else if (RHSContainsUndef) { |
0 |
9908 |
} else if (RHSContainsUndef) { |
0 |
| 9909 |
for (const APInt &L : LHSAAPVS) { |
0 |
9909 |
for (const APInt &L : LHSAAPVS) { |
0 |
| 9910 |
if (!calculateBinaryOperatorAndTakeUnion(BinOp, L, Zero)) |
0 |
9910 |
if (!calculateBinaryOperatorAndTakeUnion(BinOp, L, Zero)) |
0 |
| 9911 |
return indicatePessimisticFixpoint(); |
0 |
9911 |
return indicatePessimisticFixpoint(); |
0 |
| 9912 |
} |
--- |
9912 |
} |
--- |
| 9913 |
} else { |
--- |
9913 |
} else { |
--- |
| 9914 |
for (const APInt &L : LHSAAPVS) { |
0 |
9914 |
for (const APInt &L : LHSAAPVS) { |
0 |
| 9915 |
for (const APInt &R : RHSAAPVS) { |
0 |
9915 |
for (const APInt &R : RHSAAPVS) { |
0 |
| 9916 |
if (!calculateBinaryOperatorAndTakeUnion(BinOp, L, R)) |
0 |
9916 |
if (!calculateBinaryOperatorAndTakeUnion(BinOp, L, R)) |
0 |
| 9917 |
return indicatePessimisticFixpoint(); |
0 |
9917 |
return indicatePessimisticFixpoint(); |
0 |
| 9918 |
} |
--- |
9918 |
} |
--- |
| 9919 |
} |
--- |
9919 |
} |
--- |
| 9920 |
} |
--- |
9920 |
} |
--- |
| 9921 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
9921 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
| 9922 |
: ChangeStatus::CHANGED; |
0 |
9922 |
: ChangeStatus::CHANGED; |
0 |
| 9923 |
} |
0 |
9923 |
} |
0 |
| 9924 |
|
--- |
9924 |
|
--- |
| 9925 |
ChangeStatus updateWithInstruction(Attributor &A, Instruction *Inst) { |
0 |
9925 |
ChangeStatus updateWithInstruction(Attributor &A, Instruction *Inst) { |
0 |
| 9926 |
auto AssumedBefore = getAssumed(); |
0 |
9926 |
auto AssumedBefore = getAssumed(); |
0 |
| 9927 |
SetTy Incoming; |
0 |
9927 |
SetTy Incoming; |
0 |
| 9928 |
bool ContainsUndef; |
--- |
9928 |
bool ContainsUndef; |
--- |
| 9929 |
if (!fillSetWithConstantValues(A, IRPosition::value(*Inst), Incoming, |
0 |
9929 |
if (!fillSetWithConstantValues(A, IRPosition::value(*Inst), Incoming, |
0 |
| 9930 |
ContainsUndef, /* ForSelf */ true)) |
--- |
9930 |
ContainsUndef, /* ForSelf */ true)) |
--- |
| 9931 |
return indicatePessimisticFixpoint(); |
0 |
9931 |
return indicatePessimisticFixpoint(); |
0 |
| 9932 |
if (ContainsUndef) { |
0 |
9932 |
if (ContainsUndef) { |
0 |
| 9933 |
unionAssumedWithUndef(); |
0 |
9933 |
unionAssumedWithUndef(); |
0 |
| 9934 |
} else { |
--- |
9934 |
} else { |
--- |
| 9935 |
for (const auto &It : Incoming) |
0 |
9935 |
for (const auto &It : Incoming) |
0 |
| 9936 |
unionAssumed(It); |
0 |
9936 |
unionAssumed(It); |
0 |
| 9937 |
} |
--- |
9937 |
} |
--- |
| 9938 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
9938 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
| 9939 |
: ChangeStatus::CHANGED; |
0 |
9939 |
: ChangeStatus::CHANGED; |
0 |
| 9940 |
} |
0 |
9940 |
} |
0 |
| 9941 |
|
--- |
9941 |
|
--- |
| 9942 |
/// See AbstractAttribute::updateImpl(...). |
--- |
9942 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 9943 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
9943 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 9944 |
Value &V = getAssociatedValue(); |
0 |
9944 |
Value &V = getAssociatedValue(); |
0 |
| 9945 |
Instruction *I = dyn_cast(&V); |
0 |
9945 |
Instruction *I = dyn_cast(&V); |
0 |
| 9946 |
|
--- |
9946 |
|
--- |
| 9947 |
if (auto *ICI = dyn_cast(I)) |
0 |
9947 |
if (auto *ICI = dyn_cast(I)) |
0 |
| 9948 |
return updateWithICmpInst(A, ICI); |
0 |
9948 |
return updateWithICmpInst(A, ICI); |
0 |
| 9949 |
|
--- |
9949 |
|
--- |
| 9950 |
if (auto *SI = dyn_cast(I)) |
0 |
9950 |
if (auto *SI = dyn_cast(I)) |
0 |
| 9951 |
return updateWithSelectInst(A, SI); |
0 |
9951 |
return updateWithSelectInst(A, SI); |
0 |
| 9952 |
|
--- |
9952 |
|
--- |
| 9953 |
if (auto *CI = dyn_cast(I)) |
0 |
9953 |
if (auto *CI = dyn_cast(I)) |
0 |
| 9954 |
return updateWithCastInst(A, CI); |
0 |
9954 |
return updateWithCastInst(A, CI); |
0 |
| 9955 |
|
--- |
9955 |
|
--- |
| 9956 |
if (auto *BinOp = dyn_cast(I)) |
0 |
9956 |
if (auto *BinOp = dyn_cast(I)) |
0 |
| 9957 |
return updateWithBinaryOperator(A, BinOp); |
0 |
9957 |
return updateWithBinaryOperator(A, BinOp); |
0 |
| 9958 |
|
--- |
9958 |
|
--- |
| 9959 |
if (isa(I) || isa(I)) |
0 |
9959 |
if (isa(I) || isa(I)) |
0 |
| 9960 |
return updateWithInstruction(A, I); |
0 |
9960 |
return updateWithInstruction(A, I); |
0 |
| 9961 |
|
--- |
9961 |
|
--- |
| 9962 |
return indicatePessimisticFixpoint(); |
0 |
9962 |
return indicatePessimisticFixpoint(); |
0 |
| 9963 |
} |
--- |
9963 |
} |
--- |
| 9964 |
|
--- |
9964 |
|
--- |
| 9965 |
/// See AbstractAttribute::trackStatistics() |
--- |
9965 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9966 |
void trackStatistics() const override { |
0 |
9966 |
void trackStatistics() const override { |
0 |
| 9967 |
STATS_DECLTRACK_FLOATING_ATTR(potential_values) |
0 |
9967 |
STATS_DECLTRACK_FLOATING_ATTR(potential_values) |
0 |
| 9968 |
} |
0 |
9968 |
} |
0 |
| 9969 |
}; |
--- |
9969 |
}; |
--- |
| 9970 |
|
--- |
9970 |
|
--- |
| 9971 |
struct AAPotentialConstantValuesFunction : AAPotentialConstantValuesImpl { |
--- |
9971 |
struct AAPotentialConstantValuesFunction : AAPotentialConstantValuesImpl { |
--- |
| 9972 |
AAPotentialConstantValuesFunction(const IRPosition &IRP, Attributor &A) |
--- |
9972 |
AAPotentialConstantValuesFunction(const IRPosition &IRP, Attributor &A) |
--- |
| 9973 |
: AAPotentialConstantValuesImpl(IRP, A) {} |
--- |
9973 |
: AAPotentialConstantValuesImpl(IRP, A) {} |
--- |
| 9974 |
|
--- |
9974 |
|
--- |
| 9975 |
/// See AbstractAttribute::initialize(...). |
--- |
9975 |
/// See AbstractAttribute::initialize(...). |
--- |
| 9976 |
ChangeStatus updateImpl(Attributor &A) override { |
--- |
9976 |
ChangeStatus updateImpl(Attributor &A) override { |
--- |
| 9977 |
llvm_unreachable( |
--- |
9977 |
llvm_unreachable( |
--- |
| 9978 |
"AAPotentialConstantValues(Function|CallSite)::updateImpl will " |
--- |
9978 |
"AAPotentialConstantValues(Function|CallSite)::updateImpl will " |
--- |
| 9979 |
"not be called"); |
--- |
9979 |
"not be called"); |
--- |
| 9980 |
} |
--- |
9980 |
} |
--- |
| 9981 |
|
--- |
9981 |
|
--- |
| 9982 |
/// See AbstractAttribute::trackStatistics() |
--- |
9982 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9983 |
void trackStatistics() const override { |
--- |
9983 |
void trackStatistics() const override { |
--- |
| 9984 |
STATS_DECLTRACK_FN_ATTR(potential_values) |
--- |
9984 |
STATS_DECLTRACK_FN_ATTR(potential_values) |
--- |
| 9985 |
} |
--- |
9985 |
} |
--- |
| 9986 |
}; |
--- |
9986 |
}; |
--- |
| 9987 |
|
--- |
9987 |
|
--- |
| 9988 |
struct AAPotentialConstantValuesCallSite : AAPotentialConstantValuesFunction { |
--- |
9988 |
struct AAPotentialConstantValuesCallSite : AAPotentialConstantValuesFunction { |
--- |
| 9989 |
AAPotentialConstantValuesCallSite(const IRPosition &IRP, Attributor &A) |
--- |
9989 |
AAPotentialConstantValuesCallSite(const IRPosition &IRP, Attributor &A) |
--- |
| 9990 |
: AAPotentialConstantValuesFunction(IRP, A) {} |
--- |
9990 |
: AAPotentialConstantValuesFunction(IRP, A) {} |
--- |
| 9991 |
|
--- |
9991 |
|
--- |
| 9992 |
/// See AbstractAttribute::trackStatistics() |
--- |
9992 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 9993 |
void trackStatistics() const override { |
--- |
9993 |
void trackStatistics() const override { |
--- |
| 9994 |
STATS_DECLTRACK_CS_ATTR(potential_values) |
--- |
9994 |
STATS_DECLTRACK_CS_ATTR(potential_values) |
--- |
| 9995 |
} |
--- |
9995 |
} |
--- |
| 9996 |
}; |
--- |
9996 |
}; |
--- |
| 9997 |
|
--- |
9997 |
|
--- |
| 9998 |
struct AAPotentialConstantValuesCallSiteReturned |
--- |
9998 |
struct AAPotentialConstantValuesCallSiteReturned |
--- |
| 9999 |
: AACallSiteReturnedFromReturned
| --- |
9999 |
: AACallSiteReturnedFromReturned
| --- |
| |
| 10000 |
AAPotentialConstantValuesImpl> { |
--- |
10000 |
AAPotentialConstantValuesImpl> { |
--- |
| 10001 |
AAPotentialConstantValuesCallSiteReturned(const IRPosition &IRP, |
0 |
10001 |
AAPotentialConstantValuesCallSiteReturned(const IRPosition &IRP, |
0 |
| 10002 |
Attributor &A) |
--- |
10002 |
Attributor &A) |
--- |
| 10003 |
: AACallSiteReturnedFromReturned
| --- |
10003 |
: AACallSiteReturnedFromReturned
| --- |
| |
| 10004 |
AAPotentialConstantValuesImpl>(IRP, A) {} |
0 |
10004 |
AAPotentialConstantValuesImpl>(IRP, A) {} |
0 |
| 10005 |
|
--- |
10005 |
|
--- |
| 10006 |
/// See AbstractAttribute::trackStatistics() |
--- |
10006 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10007 |
void trackStatistics() const override { |
0 |
10007 |
void trackStatistics() const override { |
0 |
| 10008 |
STATS_DECLTRACK_CSRET_ATTR(potential_values) |
0 |
10008 |
STATS_DECLTRACK_CSRET_ATTR(potential_values) |
0 |
| 10009 |
} |
0 |
10009 |
} |
0 |
| 10010 |
}; |
--- |
10010 |
}; |
--- |
| 10011 |
|
--- |
10011 |
|
--- |
| 10012 |
struct AAPotentialConstantValuesCallSiteArgument |
--- |
10012 |
struct AAPotentialConstantValuesCallSiteArgument |
--- |
| 10013 |
: AAPotentialConstantValuesFloating { |
--- |
10013 |
: AAPotentialConstantValuesFloating { |
--- |
| 10014 |
AAPotentialConstantValuesCallSiteArgument(const IRPosition &IRP, |
0 |
10014 |
AAPotentialConstantValuesCallSiteArgument(const IRPosition &IRP, |
0 |
| 10015 |
Attributor &A) |
--- |
10015 |
Attributor &A) |
--- |
| 10016 |
: AAPotentialConstantValuesFloating(IRP, A) {} |
0 |
10016 |
: AAPotentialConstantValuesFloating(IRP, A) {} |
0 |
| 10017 |
|
--- |
10017 |
|
--- |
| 10018 |
/// See AbstractAttribute::initialize(..). |
--- |
10018 |
/// See AbstractAttribute::initialize(..). |
--- |
| 10019 |
void initialize(Attributor &A) override { |
0 |
10019 |
void initialize(Attributor &A) override { |
0 |
| 10020 |
AAPotentialConstantValuesImpl::initialize(A); |
0 |
10020 |
AAPotentialConstantValuesImpl::initialize(A); |
0 |
| 10021 |
if (isAtFixpoint()) |
0 |
10021 |
if (isAtFixpoint()) |
0 |
| 10022 |
return; |
0 |
10022 |
return; |
0 |
| 10023 |
|
--- |
10023 |
|
--- |
| 10024 |
Value &V = getAssociatedValue(); |
0 |
10024 |
Value &V = getAssociatedValue(); |
0 |
| 10025 |
|
--- |
10025 |
|
--- |
| 10026 |
if (auto *C = dyn_cast(&V)) { |
0 |
10026 |
if (auto *C = dyn_cast(&V)) { |
0 |
| 10027 |
unionAssumed(C->getValue()); |
0 |
10027 |
unionAssumed(C->getValue()); |
0 |
| 10028 |
indicateOptimisticFixpoint(); |
0 |
10028 |
indicateOptimisticFixpoint(); |
0 |
| 10029 |
return; |
0 |
10029 |
return; |
0 |
| 10030 |
} |
--- |
10030 |
} |
--- |
| 10031 |
|
--- |
10031 |
|
--- |
| 10032 |
if (isa(&V)) { |
0 |
10032 |
if (isa(&V)) { |
0 |
| 10033 |
unionAssumedWithUndef(); |
0 |
10033 |
unionAssumedWithUndef(); |
0 |
| 10034 |
indicateOptimisticFixpoint(); |
0 |
10034 |
indicateOptimisticFixpoint(); |
0 |
| 10035 |
return; |
0 |
10035 |
return; |
0 |
| 10036 |
} |
--- |
10036 |
} |
--- |
| 10037 |
} |
--- |
10037 |
} |
--- |
| 10038 |
|
--- |
10038 |
|
--- |
| 10039 |
/// See AbstractAttribute::updateImpl(...). |
--- |
10039 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 10040 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
10040 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 10041 |
Value &V = getAssociatedValue(); |
0 |
10041 |
Value &V = getAssociatedValue(); |
0 |
| 10042 |
auto AssumedBefore = getAssumed(); |
0 |
10042 |
auto AssumedBefore = getAssumed(); |
0 |
| 10043 |
auto *AA = A.getAAFor( |
0 |
10043 |
auto *AA = A.getAAFor( |
0 |
| 10044 |
*this, IRPosition::value(V), DepClassTy::REQUIRED); |
0 |
10044 |
*this, IRPosition::value(V), DepClassTy::REQUIRED); |
0 |
| 10045 |
if (!AA) |
0 |
10045 |
if (!AA) |
0 |
| 10046 |
return indicatePessimisticFixpoint(); |
0 |
10046 |
return indicatePessimisticFixpoint(); |
0 |
| 10047 |
const auto &S = AA->getAssumed(); |
0 |
10047 |
const auto &S = AA->getAssumed(); |
0 |
| 10048 |
unionAssumed(S); |
0 |
10048 |
unionAssumed(S); |
0 |
| 10049 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
10049 |
return AssumedBefore == getAssumed() ? ChangeStatus::UNCHANGED |
0 |
| 10050 |
: ChangeStatus::CHANGED; |
0 |
10050 |
: ChangeStatus::CHANGED; |
0 |
| 10051 |
} |
0 |
10051 |
} |
0 |
| 10052 |
|
--- |
10052 |
|
--- |
| 10053 |
/// See AbstractAttribute::trackStatistics() |
--- |
10053 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10054 |
void trackStatistics() const override { |
0 |
10054 |
void trackStatistics() const override { |
0 |
| 10055 |
STATS_DECLTRACK_CSARG_ATTR(potential_values) |
0 |
10055 |
STATS_DECLTRACK_CSARG_ATTR(potential_values) |
0 |
| 10056 |
} |
0 |
10056 |
} |
0 |
| 10057 |
}; |
--- |
10057 |
}; |
--- |
| 10058 |
} // namespace |
--- |
10058 |
} // namespace |
--- |
| 10059 |
|
--- |
10059 |
|
--- |
| 10060 |
/// ------------------------ NoUndef Attribute --------------------------------- |
--- |
10060 |
/// ------------------------ NoUndef Attribute --------------------------------- |
--- |
| 10061 |
bool AANoUndef::isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
10061 |
bool AANoUndef::isImpliedByIR(Attributor &A, const IRPosition &IRP, |
0 |
| 10062 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
10062 |
Attribute::AttrKind ImpliedAttributeKind, |
--- |
| 10063 |
bool IgnoreSubsumingPositions) { |
--- |
10063 |
bool IgnoreSubsumingPositions) { |
--- |
| 10064 |
assert(ImpliedAttributeKind == Attribute::NoUndef && |
0 |
10064 |
assert(ImpliedAttributeKind == Attribute::NoUndef && |
0 |
| 10065 |
"Unexpected attribute kind"); |
--- |
10065 |
"Unexpected attribute kind"); |
--- |
| 10066 |
if (A.hasAttr(IRP, {Attribute::NoUndef}, IgnoreSubsumingPositions, |
0 |
10066 |
if (A.hasAttr(IRP, {Attribute::NoUndef}, IgnoreSubsumingPositions, |
0 |
| 10067 |
Attribute::NoUndef)) |
--- |
10067 |
Attribute::NoUndef)) |
--- |
| 10068 |
return true; |
0 |
10068 |
return true; |
0 |
| 10069 |
|
--- |
10069 |
|
--- |
| 10070 |
Value &Val = IRP.getAssociatedValue(); |
0 |
10070 |
Value &Val = IRP.getAssociatedValue(); |
0 |
| 10071 |
if (IRP.getPositionKind() != IRPosition::IRP_RETURNED && |
0 |
10071 |
if (IRP.getPositionKind() != IRPosition::IRP_RETURNED && |
0 |
| 10072 |
isGuaranteedNotToBeUndefOrPoison(&Val)) { |
0 |
10072 |
isGuaranteedNotToBeUndefOrPoison(&Val)) { |
0 |
| 10073 |
LLVMContext &Ctx = Val.getContext(); |
0 |
10073 |
LLVMContext &Ctx = Val.getContext(); |
0 |
| 10074 |
A.manifestAttrs(IRP, Attribute::get(Ctx, Attribute::NoUndef)); |
0 |
10074 |
A.manifestAttrs(IRP, Attribute::get(Ctx, Attribute::NoUndef)); |
0 |
| 10075 |
return true; |
0 |
10075 |
return true; |
0 |
| 10076 |
} |
--- |
10076 |
} |
--- |
| 10077 |
|
--- |
10077 |
|
--- |
| 10078 |
return false; |
0 |
10078 |
return false; |
0 |
| 10079 |
} |
--- |
10079 |
} |
--- |
| 10080 |
|
--- |
10080 |
|
--- |
| 10081 |
namespace { |
--- |
10081 |
namespace { |
--- |
| 10082 |
struct AANoUndefImpl : AANoUndef { |
--- |
10082 |
struct AANoUndefImpl : AANoUndef { |
--- |
| 10083 |
AANoUndefImpl(const IRPosition &IRP, Attributor &A) : AANoUndef(IRP, A) {} |
0 |
10083 |
AANoUndefImpl(const IRPosition &IRP, Attributor &A) : AANoUndef(IRP, A) {} |
0 |
| 10084 |
|
--- |
10084 |
|
--- |
| 10085 |
/// See AbstractAttribute::initialize(...). |
--- |
10085 |
/// See AbstractAttribute::initialize(...). |
--- |
| 10086 |
void initialize(Attributor &A) override { |
0 |
10086 |
void initialize(Attributor &A) override { |
0 |
| 10087 |
Value &V = getAssociatedValue(); |
0 |
10087 |
Value &V = getAssociatedValue(); |
0 |
| 10088 |
if (isa(V)) |
0 |
10088 |
if (isa(V)) |
0 |
| 10089 |
indicatePessimisticFixpoint(); |
0 |
10089 |
indicatePessimisticFixpoint(); |
0 |
| 10090 |
assert(!isImpliedByIR(A, getIRPosition(), Attribute::NoUndef)); |
0 |
10090 |
assert(!isImpliedByIR(A, getIRPosition(), Attribute::NoUndef)); |
0 |
| 10091 |
} |
0 |
10091 |
} |
0 |
| 10092 |
|
--- |
10092 |
|
--- |
| 10093 |
/// See followUsesInMBEC |
--- |
10093 |
/// See followUsesInMBEC |
--- |
| 10094 |
bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I, |
0 |
10094 |
bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I, |
0 |
| 10095 |
AANoUndef::StateType &State) { |
--- |
10095 |
AANoUndef::StateType &State) { |
--- |
| 10096 |
const Value *UseV = U->get(); |
0 |
10096 |
const Value *UseV = U->get(); |
0 |
| 10097 |
const DominatorTree *DT = nullptr; |
0 |
10097 |
const DominatorTree *DT = nullptr; |
0 |
| 10098 |
AssumptionCache *AC = nullptr; |
0 |
10098 |
AssumptionCache *AC = nullptr; |
0 |
| 10099 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
10099 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
| 10100 |
if (Function *F = getAnchorScope()) { |
0 |
10100 |
if (Function *F = getAnchorScope()) { |
0 |
| 10101 |
DT = InfoCache.getAnalysisResultForFunction(*F); |
0 |
10101 |
DT = InfoCache.getAnalysisResultForFunction(*F); |
0 |
| 10102 |
AC = InfoCache.getAnalysisResultForFunction(*F); |
0 |
10102 |
AC = InfoCache.getAnalysisResultForFunction(*F); |
0 |
| 10103 |
} |
--- |
10103 |
} |
--- |
| 10104 |
State.setKnown(isGuaranteedNotToBeUndefOrPoison(UseV, AC, I, DT)); |
0 |
10104 |
State.setKnown(isGuaranteedNotToBeUndefOrPoison(UseV, AC, I, DT)); |
0 |
| 10105 |
bool TrackUse = false; |
0 |
10105 |
bool TrackUse = false; |
0 |
| 10106 |
// Track use for instructions which must produce undef or poison bits when |
--- |
10106 |
// Track use for instructions which must produce undef or poison bits when |
--- |
| 10107 |
// at least one operand contains such bits. |
--- |
10107 |
// at least one operand contains such bits. |
--- |
| 10108 |
if (isa(*I) || isa(*I)) |
0 |
10108 |
if (isa(*I) || isa(*I)) |
0 |
| 10109 |
TrackUse = true; |
0 |
10109 |
TrackUse = true; |
0 |
| 10110 |
return TrackUse; |
0 |
10110 |
return TrackUse; |
0 |
| 10111 |
} |
--- |
10111 |
} |
--- |
| 10112 |
|
--- |
10112 |
|
--- |
| 10113 |
/// See AbstractAttribute::getAsStr(). |
--- |
10113 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 10114 |
const std::string getAsStr(Attributor *A) const override { |
0 |
10114 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 10115 |
return getAssumed() ? "noundef" : "may-undef-or-poison"; |
0 |
10115 |
return getAssumed() ? "noundef" : "may-undef-or-poison"; |
0 |
| 10116 |
} |
--- |
10116 |
} |
--- |
| 10117 |
|
--- |
10117 |
|
--- |
| 10118 |
ChangeStatus manifest(Attributor &A) override { |
0 |
10118 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 10119 |
// We don't manifest noundef attribute for dead positions because the |
--- |
10119 |
// We don't manifest noundef attribute for dead positions because the |
--- |
| 10120 |
// associated values with dead positions would be replaced with undef |
--- |
10120 |
// associated values with dead positions would be replaced with undef |
--- |
| 10121 |
// values. |
--- |
10121 |
// values. |
--- |
| 10122 |
bool UsedAssumedInformation = false; |
0 |
10122 |
bool UsedAssumedInformation = false; |
0 |
| 10123 |
if (A.isAssumedDead(getIRPosition(), nullptr, nullptr, |
0 |
10123 |
if (A.isAssumedDead(getIRPosition(), nullptr, nullptr, |
0 |
| 10124 |
UsedAssumedInformation)) |
--- |
10124 |
UsedAssumedInformation)) |
--- |
| 10125 |
return ChangeStatus::UNCHANGED; |
0 |
10125 |
return ChangeStatus::UNCHANGED; |
0 |
| 10126 |
// A position whose simplified value does not have any value is |
--- |
10126 |
// A position whose simplified value does not have any value is |
--- |
| 10127 |
// considered to be dead. We don't manifest noundef in such positions for |
--- |
10127 |
// considered to be dead. We don't manifest noundef in such positions for |
--- |
| 10128 |
// the same reason above. |
--- |
10128 |
// the same reason above. |
--- |
| 10129 |
if (!A.getAssumedSimplified(getIRPosition(), *this, UsedAssumedInformation, |
0 |
10129 |
if (!A.getAssumedSimplified(getIRPosition(), *this, UsedAssumedInformation, |
0 |
| 10130 |
AA::Interprocedural) |
--- |
10130 |
AA::Interprocedural) |
--- |
| 10131 |
.has_value()) |
0 |
10131 |
.has_value()) |
0 |
| 10132 |
return ChangeStatus::UNCHANGED; |
0 |
10132 |
return ChangeStatus::UNCHANGED; |
0 |
| 10133 |
return AANoUndef::manifest(A); |
0 |
10133 |
return AANoUndef::manifest(A); |
0 |
| 10134 |
} |
--- |
10134 |
} |
--- |
| 10135 |
}; |
--- |
10135 |
}; |
--- |
| 10136 |
|
--- |
10136 |
|
--- |
| 10137 |
struct AANoUndefFloating : public AANoUndefImpl { |
--- |
10137 |
struct AANoUndefFloating : public AANoUndefImpl { |
--- |
| 10138 |
AANoUndefFloating(const IRPosition &IRP, Attributor &A) |
0 |
10138 |
AANoUndefFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 10139 |
: AANoUndefImpl(IRP, A) {} |
0 |
10139 |
: AANoUndefImpl(IRP, A) {} |
0 |
| 10140 |
|
--- |
10140 |
|
--- |
| 10141 |
/// See AbstractAttribute::initialize(...). |
--- |
10141 |
/// See AbstractAttribute::initialize(...). |
--- |
| 10142 |
void initialize(Attributor &A) override { |
0 |
10142 |
void initialize(Attributor &A) override { |
0 |
| 10143 |
AANoUndefImpl::initialize(A); |
0 |
10143 |
AANoUndefImpl::initialize(A); |
0 |
| 10144 |
if (!getState().isAtFixpoint()) |
0 |
10144 |
if (!getState().isAtFixpoint()) |
0 |
| 10145 |
if (Instruction *CtxI = getCtxI()) |
0 |
10145 |
if (Instruction *CtxI = getCtxI()) |
0 |
| 10146 |
followUsesInMBEC(*this, A, getState(), *CtxI); |
0 |
10146 |
followUsesInMBEC(*this, A, getState(), *CtxI); |
0 |
| 10147 |
} |
0 |
10147 |
} |
0 |
| 10148 |
|
--- |
10148 |
|
--- |
| 10149 |
/// See AbstractAttribute::updateImpl(...). |
--- |
10149 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 10150 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
10150 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 10151 |
auto VisitValueCB = [&](const IRPosition &IRP) -> bool { |
0 |
10151 |
auto VisitValueCB = [&](const IRPosition &IRP) -> bool { |
0 |
| 10152 |
bool IsKnownNoUndef; |
--- |
10152 |
bool IsKnownNoUndef; |
--- |
| 10153 |
return AA::hasAssumedIRAttr( |
0 |
10153 |
return AA::hasAssumedIRAttr( |
0 |
| 10154 |
A, this, IRP, DepClassTy::REQUIRED, IsKnownNoUndef); |
0 |
10154 |
A, this, IRP, DepClassTy::REQUIRED, IsKnownNoUndef); |
0 |
| 10155 |
}; |
0 |
10155 |
}; |
0 |
| 10156 |
|
--- |
10156 |
|
--- |
| 10157 |
bool Stripped; |
--- |
10157 |
bool Stripped; |
--- |
| 10158 |
bool UsedAssumedInformation = false; |
0 |
10158 |
bool UsedAssumedInformation = false; |
0 |
| 10159 |
Value *AssociatedValue = &getAssociatedValue(); |
0 |
10159 |
Value *AssociatedValue = &getAssociatedValue(); |
0 |
| 10160 |
SmallVector Values; |
0 |
10160 |
SmallVector Values; |
0 |
| 10161 |
if (!A.getAssumedSimplifiedValues(getIRPosition(), *this, Values, |
0 |
10161 |
if (!A.getAssumedSimplifiedValues(getIRPosition(), *this, Values, |
0 |
| 10162 |
AA::AnyScope, UsedAssumedInformation)) |
--- |
10162 |
AA::AnyScope, UsedAssumedInformation)) |
--- |
| 10163 |
Stripped = false; |
0 |
10163 |
Stripped = false; |
0 |
| 10164 |
else |
--- |
10164 |
else |
--- |
| 10165 |
Stripped = |
0 |
10165 |
Stripped = |
0 |
| 10166 |
Values.size() != 1 || Values.front().getValue() != AssociatedValue; |
0 |
10166 |
Values.size() != 1 || Values.front().getValue() != AssociatedValue; |
0 |
| 10167 |
|
--- |
10167 |
|
--- |
| 10168 |
if (!Stripped) { |
0 |
10168 |
if (!Stripped) { |
0 |
| 10169 |
// If we haven't stripped anything we might still be able to use a |
--- |
10169 |
// If we haven't stripped anything we might still be able to use a |
--- |
| 10170 |
// different AA, but only if the IRP changes. Effectively when we |
--- |
10170 |
// different AA, but only if the IRP changes. Effectively when we |
--- |
| 10171 |
// interpret this not as a call site value but as a floating/argument |
--- |
10171 |
// interpret this not as a call site value but as a floating/argument |
--- |
| 10172 |
// value. |
--- |
10172 |
// value. |
--- |
| 10173 |
const IRPosition AVIRP = IRPosition::value(*AssociatedValue); |
0 |
10173 |
const IRPosition AVIRP = IRPosition::value(*AssociatedValue); |
0 |
| 10174 |
if (AVIRP == getIRPosition() || !VisitValueCB(AVIRP)) |
0 |
10174 |
if (AVIRP == getIRPosition() || !VisitValueCB(AVIRP)) |
0 |
| 10175 |
return indicatePessimisticFixpoint(); |
0 |
10175 |
return indicatePessimisticFixpoint(); |
0 |
| 10176 |
return ChangeStatus::UNCHANGED; |
0 |
10176 |
return ChangeStatus::UNCHANGED; |
0 |
| 10177 |
} |
--- |
10177 |
} |
--- |
| 10178 |
|
--- |
10178 |
|
--- |
| 10179 |
for (const auto &VAC : Values) |
0 |
10179 |
for (const auto &VAC : Values) |
0 |
| 10180 |
if (!VisitValueCB(IRPosition::value(*VAC.getValue()))) |
0 |
10180 |
if (!VisitValueCB(IRPosition::value(*VAC.getValue()))) |
0 |
| 10181 |
return indicatePessimisticFixpoint(); |
0 |
10181 |
return indicatePessimisticFixpoint(); |
0 |
| 10182 |
|
--- |
10182 |
|
--- |
| 10183 |
return ChangeStatus::UNCHANGED; |
0 |
10183 |
return ChangeStatus::UNCHANGED; |
0 |
| 10184 |
} |
0 |
10184 |
} |
0 |
| 10185 |
|
--- |
10185 |
|
--- |
| 10186 |
/// See AbstractAttribute::trackStatistics() |
--- |
10186 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10187 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(noundef) } |
0 |
10187 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(noundef) } |
0 |
| 10188 |
}; |
--- |
10188 |
}; |
--- |
| 10189 |
|
--- |
10189 |
|
--- |
| 10190 |
struct AANoUndefReturned final |
--- |
10190 |
struct AANoUndefReturned final |
--- |
| 10191 |
: AAReturnedFromReturnedValues
| --- |
10191 |
: AAReturnedFromReturnedValues
| --- |
| |
| 10192 |
AANoUndef::StateType, false, |
--- |
10192 |
AANoUndef::StateType, false, |
--- |
| 10193 |
Attribute::NoUndef> { |
--- |
10193 |
Attribute::NoUndef> { |
--- |
| 10194 |
AANoUndefReturned(const IRPosition &IRP, Attributor &A) |
0 |
10194 |
AANoUndefReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 10195 |
: AAReturnedFromReturnedValues
| --- |
10195 |
: AAReturnedFromReturnedValues
| --- |
| |
| 10196 |
AANoUndef::StateType, false, |
--- |
10196 |
AANoUndef::StateType, false, |
--- |
| 10197 |
Attribute::NoUndef>(IRP, A) {} |
0 |
10197 |
Attribute::NoUndef>(IRP, A) {} |
0 |
| 10198 |
|
--- |
10198 |
|
--- |
| 10199 |
/// See AbstractAttribute::trackStatistics() |
--- |
10199 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10200 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(noundef) } |
0 |
10200 |
void trackStatistics() const override { STATS_DECLTRACK_FNRET_ATTR(noundef) } |
0 |
| 10201 |
}; |
--- |
10201 |
}; |
--- |
| 10202 |
|
--- |
10202 |
|
--- |
| 10203 |
struct AANoUndefArgument final |
--- |
10203 |
struct AANoUndefArgument final |
--- |
| 10204 |
: AAArgumentFromCallSiteArguments
| --- |
10204 |
: AAArgumentFromCallSiteArguments
| --- |
| |
| 10205 |
AANoUndef::StateType, false, |
--- |
10205 |
AANoUndef::StateType, false, |
--- |
| 10206 |
Attribute::NoUndef> { |
--- |
10206 |
Attribute::NoUndef> { |
--- |
| 10207 |
AANoUndefArgument(const IRPosition &IRP, Attributor &A) |
0 |
10207 |
AANoUndefArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 10208 |
: AAArgumentFromCallSiteArguments
| --- |
10208 |
: AAArgumentFromCallSiteArguments
| --- |
| |
| 10209 |
AANoUndef::StateType, false, |
--- |
10209 |
AANoUndef::StateType, false, |
--- |
| 10210 |
Attribute::NoUndef>(IRP, A) {} |
0 |
10210 |
Attribute::NoUndef>(IRP, A) {} |
0 |
| 10211 |
|
--- |
10211 |
|
--- |
| 10212 |
/// See AbstractAttribute::trackStatistics() |
--- |
10212 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10213 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(noundef) } |
0 |
10213 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(noundef) } |
0 |
| 10214 |
}; |
--- |
10214 |
}; |
--- |
| 10215 |
|
--- |
10215 |
|
--- |
| 10216 |
struct AANoUndefCallSiteArgument final : AANoUndefFloating { |
--- |
10216 |
struct AANoUndefCallSiteArgument final : AANoUndefFloating { |
--- |
| 10217 |
AANoUndefCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
10217 |
AANoUndefCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 10218 |
: AANoUndefFloating(IRP, A) {} |
0 |
10218 |
: AANoUndefFloating(IRP, A) {} |
0 |
| 10219 |
|
--- |
10219 |
|
--- |
| 10220 |
/// See AbstractAttribute::trackStatistics() |
--- |
10220 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10221 |
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(noundef) } |
0 |
10221 |
void trackStatistics() const override { STATS_DECLTRACK_CSARG_ATTR(noundef) } |
0 |
| 10222 |
}; |
--- |
10222 |
}; |
--- |
| 10223 |
|
--- |
10223 |
|
--- |
| 10224 |
struct AANoUndefCallSiteReturned final |
--- |
10224 |
struct AANoUndefCallSiteReturned final |
--- |
| 10225 |
: AACallSiteReturnedFromReturned
| --- |
10225 |
: AACallSiteReturnedFromReturned
| --- |
| |
| 10226 |
AANoUndef::StateType, false, |
--- |
10226 |
AANoUndef::StateType, false, |
--- |
| 10227 |
Attribute::NoUndef> { |
--- |
10227 |
Attribute::NoUndef> { |
--- |
| 10228 |
AANoUndefCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
10228 |
AANoUndefCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 10229 |
: AACallSiteReturnedFromReturned
| --- |
10229 |
: AACallSiteReturnedFromReturned
| --- |
| |
| 10230 |
AANoUndef::StateType, false, |
--- |
10230 |
AANoUndef::StateType, false, |
--- |
| 10231 |
Attribute::NoUndef>(IRP, A) {} |
0 |
10231 |
Attribute::NoUndef>(IRP, A) {} |
0 |
| 10232 |
|
--- |
10232 |
|
--- |
| 10233 |
/// See AbstractAttribute::trackStatistics() |
--- |
10233 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10234 |
void trackStatistics() const override { STATS_DECLTRACK_CSRET_ATTR(noundef) } |
0 |
10234 |
void trackStatistics() const override { STATS_DECLTRACK_CSRET_ATTR(noundef) } |
0 |
| 10235 |
}; |
--- |
10235 |
}; |
--- |
| 10236 |
|
--- |
10236 |
|
--- |
| 10237 |
/// ------------------------ NoFPClass Attribute ------------------------------- |
--- |
10237 |
/// ------------------------ NoFPClass Attribute ------------------------------- |
--- |
| 10238 |
|
--- |
10238 |
|
--- |
| 10239 |
struct AANoFPClassImpl : AANoFPClass { |
--- |
10239 |
struct AANoFPClassImpl : AANoFPClass { |
--- |
| 10240 |
AANoFPClassImpl(const IRPosition &IRP, Attributor &A) : AANoFPClass(IRP, A) {} |
0 |
10240 |
AANoFPClassImpl(const IRPosition &IRP, Attributor &A) : AANoFPClass(IRP, A) {} |
0 |
| 10241 |
|
--- |
10241 |
|
--- |
| 10242 |
void initialize(Attributor &A) override { |
0 |
10242 |
void initialize(Attributor &A) override { |
0 |
| 10243 |
const IRPosition &IRP = getIRPosition(); |
0 |
10243 |
const IRPosition &IRP = getIRPosition(); |
0 |
| 10244 |
|
--- |
10244 |
|
--- |
| 10245 |
Value &V = IRP.getAssociatedValue(); |
0 |
10245 |
Value &V = IRP.getAssociatedValue(); |
0 |
| 10246 |
if (isa(V)) { |
0 |
10246 |
if (isa(V)) { |
0 |
| 10247 |
indicateOptimisticFixpoint(); |
0 |
10247 |
indicateOptimisticFixpoint(); |
0 |
| 10248 |
return; |
0 |
10248 |
return; |
0 |
| 10249 |
} |
--- |
10249 |
} |
--- |
| 10250 |
|
--- |
10250 |
|
--- |
| 10251 |
SmallVector Attrs; |
0 |
10251 |
SmallVector Attrs; |
0 |
| 10252 |
A.getAttrs(getIRPosition(), {Attribute::NoFPClass}, Attrs, false); |
0 |
10252 |
A.getAttrs(getIRPosition(), {Attribute::NoFPClass}, Attrs, false); |
0 |
| 10253 |
for (const auto &Attr : Attrs) { |
0 |
10253 |
for (const auto &Attr : Attrs) { |
0 |
| 10254 |
addKnownBits(Attr.getNoFPClass()); |
0 |
10254 |
addKnownBits(Attr.getNoFPClass()); |
0 |
| 10255 |
return; |
0 |
10255 |
return; |
0 |
| 10256 |
} |
--- |
10256 |
} |
--- |
| 10257 |
|
--- |
10257 |
|
--- |
| 10258 |
const DataLayout &DL = A.getDataLayout(); |
0 |
10258 |
const DataLayout &DL = A.getDataLayout(); |
0 |
| 10259 |
if (getPositionKind() != IRPosition::IRP_RETURNED) { |
0 |
10259 |
if (getPositionKind() != IRPosition::IRP_RETURNED) { |
0 |
| 10260 |
KnownFPClass KnownFPClass = computeKnownFPClass(&V, DL); |
0 |
10260 |
KnownFPClass KnownFPClass = computeKnownFPClass(&V, DL); |
0 |
| 10261 |
addKnownBits(~KnownFPClass.KnownFPClasses); |
0 |
10261 |
addKnownBits(~KnownFPClass.KnownFPClasses); |
0 |
| 10262 |
} |
--- |
10262 |
} |
--- |
| 10263 |
|
--- |
10263 |
|
--- |
| 10264 |
if (Instruction *CtxI = getCtxI()) |
0 |
10264 |
if (Instruction *CtxI = getCtxI()) |
0 |
| 10265 |
followUsesInMBEC(*this, A, getState(), *CtxI); |
0 |
10265 |
followUsesInMBEC(*this, A, getState(), *CtxI); |
0 |
| 10266 |
} |
0 |
10266 |
} |
0 |
| 10267 |
|
--- |
10267 |
|
--- |
| 10268 |
/// See followUsesInMBEC |
--- |
10268 |
/// See followUsesInMBEC |
--- |
| 10269 |
bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I, |
0 |
10269 |
bool followUseInMBEC(Attributor &A, const Use *U, const Instruction *I, |
0 |
| 10270 |
AANoFPClass::StateType &State) { |
--- |
10270 |
AANoFPClass::StateType &State) { |
--- |
| 10271 |
const Value *UseV = U->get(); |
0 |
10271 |
const Value *UseV = U->get(); |
0 |
| 10272 |
const DominatorTree *DT = nullptr; |
0 |
10272 |
const DominatorTree *DT = nullptr; |
0 |
| 10273 |
AssumptionCache *AC = nullptr; |
0 |
10273 |
AssumptionCache *AC = nullptr; |
0 |
| 10274 |
const TargetLibraryInfo *TLI = nullptr; |
0 |
10274 |
const TargetLibraryInfo *TLI = nullptr; |
0 |
| 10275 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
10275 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
| 10276 |
|
--- |
10276 |
|
--- |
| 10277 |
if (Function *F = getAnchorScope()) { |
0 |
10277 |
if (Function *F = getAnchorScope()) { |
0 |
| 10278 |
DT = InfoCache.getAnalysisResultForFunction(*F); |
0 |
10278 |
DT = InfoCache.getAnalysisResultForFunction(*F); |
0 |
| 10279 |
AC = InfoCache.getAnalysisResultForFunction(*F); |
0 |
10279 |
AC = InfoCache.getAnalysisResultForFunction(*F); |
0 |
| 10280 |
TLI = InfoCache.getTargetLibraryInfoForFunction(*F); |
0 |
10280 |
TLI = InfoCache.getTargetLibraryInfoForFunction(*F); |
0 |
| 10281 |
} |
--- |
10281 |
} |
--- |
| 10282 |
|
--- |
10282 |
|
--- |
| 10283 |
const DataLayout &DL = A.getDataLayout(); |
0 |
10283 |
const DataLayout &DL = A.getDataLayout(); |
0 |
| 10284 |
|
--- |
10284 |
|
--- |
| 10285 |
KnownFPClass KnownFPClass = |
--- |
10285 |
KnownFPClass KnownFPClass = |
--- |
| 10286 |
computeKnownFPClass(UseV, DL, |
0 |
10286 |
computeKnownFPClass(UseV, DL, |
0 |
| 10287 |
/*InterestedClasses=*/fcAllFlags, |
--- |
10287 |
/*InterestedClasses=*/fcAllFlags, |
--- |
| 10288 |
/*Depth=*/0, TLI, AC, I, DT); |
--- |
10288 |
/*Depth=*/0, TLI, AC, I, DT); |
--- |
| 10289 |
State.addKnownBits(~KnownFPClass.KnownFPClasses); |
0 |
10289 |
State.addKnownBits(~KnownFPClass.KnownFPClasses); |
0 |
| 10290 |
|
--- |
10290 |
|
--- |
| 10291 |
bool TrackUse = false; |
0 |
10291 |
bool TrackUse = false; |
0 |
| 10292 |
return TrackUse; |
0 |
10292 |
return TrackUse; |
0 |
| 10293 |
} |
--- |
10293 |
} |
--- |
| 10294 |
|
--- |
10294 |
|
--- |
| 10295 |
const std::string getAsStr(Attributor *A) const override { |
0 |
10295 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 10296 |
std::string Result = "nofpclass"; |
0 |
10296 |
std::string Result = "nofpclass"; |
0 |
| 10297 |
raw_string_ostream OS(Result); |
0 |
10297 |
raw_string_ostream OS(Result); |
0 |
| 10298 |
OS << getAssumedNoFPClass(); |
0 |
10298 |
OS << getAssumedNoFPClass(); |
0 |
| 10299 |
return Result; |
0 |
10299 |
return Result; |
0 |
| 10300 |
} |
0 |
10300 |
} |
0 |
| 10301 |
|
--- |
10301 |
|
--- |
| 10302 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
10302 |
void getDeducedAttributes(Attributor &A, LLVMContext &Ctx, |
0 |
| 10303 |
SmallVectorImpl &Attrs) const override { |
--- |
10303 |
SmallVectorImpl &Attrs) const override { |
--- |
| 10304 |
Attrs.emplace_back(Attribute::getWithNoFPClass(Ctx, getAssumedNoFPClass())); |
0 |
10304 |
Attrs.emplace_back(Attribute::getWithNoFPClass(Ctx, getAssumedNoFPClass())); |
0 |
| 10305 |
} |
0 |
10305 |
} |
0 |
| 10306 |
}; |
--- |
10306 |
}; |
--- |
| 10307 |
|
--- |
10307 |
|
--- |
| 10308 |
struct AANoFPClassFloating : public AANoFPClassImpl { |
--- |
10308 |
struct AANoFPClassFloating : public AANoFPClassImpl { |
--- |
| 10309 |
AANoFPClassFloating(const IRPosition &IRP, Attributor &A) |
0 |
10309 |
AANoFPClassFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 10310 |
: AANoFPClassImpl(IRP, A) {} |
0 |
10310 |
: AANoFPClassImpl(IRP, A) {} |
0 |
| 10311 |
|
--- |
10311 |
|
--- |
| 10312 |
/// See AbstractAttribute::updateImpl(...). |
--- |
10312 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 10313 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
10313 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 10314 |
SmallVector Values; |
0 |
10314 |
SmallVector Values; |
0 |
| 10315 |
bool UsedAssumedInformation = false; |
0 |
10315 |
bool UsedAssumedInformation = false; |
0 |
| 10316 |
if (!A.getAssumedSimplifiedValues(getIRPosition(), *this, Values, |
0 |
10316 |
if (!A.getAssumedSimplifiedValues(getIRPosition(), *this, Values, |
0 |
| 10317 |
AA::AnyScope, UsedAssumedInformation)) { |
--- |
10317 |
AA::AnyScope, UsedAssumedInformation)) { |
--- |
| 10318 |
Values.push_back({getAssociatedValue(), getCtxI()}); |
0 |
10318 |
Values.push_back({getAssociatedValue(), getCtxI()}); |
0 |
| 10319 |
} |
--- |
10319 |
} |
--- |
| 10320 |
|
--- |
10320 |
|
--- |
| 10321 |
StateType T; |
0 |
10321 |
StateType T; |
0 |
| 10322 |
auto VisitValueCB = [&](Value &V, const Instruction *CtxI) -> bool { |
0 |
10322 |
auto VisitValueCB = [&](Value &V, const Instruction *CtxI) -> bool { |
0 |
| 10323 |
const auto *AA = A.getAAFor(*this, IRPosition::value(V), |
0 |
10323 |
const auto *AA = A.getAAFor(*this, IRPosition::value(V), |
0 |
| 10324 |
DepClassTy::REQUIRED); |
--- |
10324 |
DepClassTy::REQUIRED); |
--- |
| 10325 |
if (!AA || this == AA) { |
0 |
10325 |
if (!AA || this == AA) { |
0 |
| 10326 |
T.indicatePessimisticFixpoint(); |
0 |
10326 |
T.indicatePessimisticFixpoint(); |
0 |
| 10327 |
} else { |
--- |
10327 |
} else { |
--- |
| 10328 |
const AANoFPClass::StateType &S = |
--- |
10328 |
const AANoFPClass::StateType &S = |
--- |
| 10329 |
static_cast(AA->getState()); |
0 |
10329 |
static_cast(AA->getState()); |
0 |
| 10330 |
T ^= S; |
0 |
10330 |
T ^= S; |
0 |
| 10331 |
} |
--- |
10331 |
} |
--- |
| 10332 |
return T.isValidState(); |
0 |
10332 |
return T.isValidState(); |
0 |
| 10333 |
}; |
0 |
10333 |
}; |
0 |
| 10334 |
|
--- |
10334 |
|
--- |
| 10335 |
for (const auto &VAC : Values) |
0 |
10335 |
for (const auto &VAC : Values) |
0 |
| 10336 |
if (!VisitValueCB(*VAC.getValue(), VAC.getCtxI())) |
0 |
10336 |
if (!VisitValueCB(*VAC.getValue(), VAC.getCtxI())) |
0 |
| 10337 |
return indicatePessimisticFixpoint(); |
0 |
10337 |
return indicatePessimisticFixpoint(); |
0 |
| 10338 |
|
--- |
10338 |
|
--- |
| 10339 |
return clampStateAndIndicateChange(getState(), T); |
0 |
10339 |
return clampStateAndIndicateChange(getState(), T); |
0 |
| 10340 |
} |
0 |
10340 |
} |
0 |
| 10341 |
|
--- |
10341 |
|
--- |
| 10342 |
/// See AbstractAttribute::trackStatistics() |
--- |
10342 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10343 |
void trackStatistics() const override { |
0 |
10343 |
void trackStatistics() const override { |
0 |
| 10344 |
STATS_DECLTRACK_FNRET_ATTR(nofpclass) |
0 |
10344 |
STATS_DECLTRACK_FNRET_ATTR(nofpclass) |
0 |
| 10345 |
} |
0 |
10345 |
} |
0 |
| 10346 |
}; |
--- |
10346 |
}; |
--- |
| 10347 |
|
--- |
10347 |
|
--- |
| 10348 |
struct AANoFPClassReturned final |
--- |
10348 |
struct AANoFPClassReturned final |
--- |
| 10349 |
: AAReturnedFromReturnedValues
| --- |
10349 |
: AAReturnedFromReturnedValues
| --- |
| |
| 10350 |
AANoFPClassImpl::StateType, false, Attribute::None, false> { |
--- |
10350 |
AANoFPClassImpl::StateType, false, Attribute::None, false> { |
--- |
| 10351 |
AANoFPClassReturned(const IRPosition &IRP, Attributor &A) |
0 |
10351 |
AANoFPClassReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 10352 |
: AAReturnedFromReturnedValues
| --- |
10352 |
: AAReturnedFromReturnedValues
| --- |
| |
| 10353 |
AANoFPClassImpl::StateType, false, Attribute::None, false>( |
--- |
10353 |
AANoFPClassImpl::StateType, false, Attribute::None, false>( |
--- |
| 10354 |
IRP, A) {} |
0 |
10354 |
IRP, A) {} |
0 |
| 10355 |
|
--- |
10355 |
|
--- |
| 10356 |
/// See AbstractAttribute::trackStatistics() |
--- |
10356 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10357 |
void trackStatistics() const override { |
0 |
10357 |
void trackStatistics() const override { |
0 |
| 10358 |
STATS_DECLTRACK_FNRET_ATTR(nofpclass) |
0 |
10358 |
STATS_DECLTRACK_FNRET_ATTR(nofpclass) |
0 |
| 10359 |
} |
0 |
10359 |
} |
0 |
| 10360 |
}; |
--- |
10360 |
}; |
--- |
| 10361 |
|
--- |
10361 |
|
--- |
| 10362 |
struct AANoFPClassArgument final |
--- |
10362 |
struct AANoFPClassArgument final |
--- |
| 10363 |
: AAArgumentFromCallSiteArguments { |
--- |
10363 |
: AAArgumentFromCallSiteArguments { |
--- |
| 10364 |
AANoFPClassArgument(const IRPosition &IRP, Attributor &A) |
0 |
10364 |
AANoFPClassArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 10365 |
: AAArgumentFromCallSiteArguments(IRP, A) {} |
0 |
10365 |
: AAArgumentFromCallSiteArguments(IRP, A) {} |
0 |
| 10366 |
|
--- |
10366 |
|
--- |
| 10367 |
/// See AbstractAttribute::trackStatistics() |
--- |
10367 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10368 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(nofpclass) } |
0 |
10368 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(nofpclass) } |
0 |
| 10369 |
}; |
--- |
10369 |
}; |
--- |
| 10370 |
|
--- |
10370 |
|
--- |
| 10371 |
struct AANoFPClassCallSiteArgument final : AANoFPClassFloating { |
--- |
10371 |
struct AANoFPClassCallSiteArgument final : AANoFPClassFloating { |
--- |
| 10372 |
AANoFPClassCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
10372 |
AANoFPClassCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 10373 |
: AANoFPClassFloating(IRP, A) {} |
0 |
10373 |
: AANoFPClassFloating(IRP, A) {} |
0 |
| 10374 |
|
--- |
10374 |
|
--- |
| 10375 |
/// See AbstractAttribute::trackStatistics() |
--- |
10375 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10376 |
void trackStatistics() const override { |
0 |
10376 |
void trackStatistics() const override { |
0 |
| 10377 |
STATS_DECLTRACK_CSARG_ATTR(nofpclass) |
0 |
10377 |
STATS_DECLTRACK_CSARG_ATTR(nofpclass) |
0 |
| 10378 |
} |
0 |
10378 |
} |
0 |
| 10379 |
}; |
--- |
10379 |
}; |
--- |
| 10380 |
|
--- |
10380 |
|
--- |
| 10381 |
struct AANoFPClassCallSiteReturned final |
--- |
10381 |
struct AANoFPClassCallSiteReturned final |
--- |
| 10382 |
: AACallSiteReturnedFromReturned { |
--- |
10382 |
: AACallSiteReturnedFromReturned { |
--- |
| 10383 |
AANoFPClassCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
10383 |
AANoFPClassCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 10384 |
: AACallSiteReturnedFromReturned(IRP, A) {} |
0 |
10384 |
: AACallSiteReturnedFromReturned(IRP, A) {} |
0 |
| 10385 |
|
--- |
10385 |
|
--- |
| 10386 |
/// See AbstractAttribute::trackStatistics() |
--- |
10386 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 10387 |
void trackStatistics() const override { |
0 |
10387 |
void trackStatistics() const override { |
0 |
| 10388 |
STATS_DECLTRACK_CSRET_ATTR(nofpclass) |
0 |
10388 |
STATS_DECLTRACK_CSRET_ATTR(nofpclass) |
0 |
| 10389 |
} |
0 |
10389 |
} |
0 |
| 10390 |
}; |
--- |
10390 |
}; |
--- |
| 10391 |
|
--- |
10391 |
|
--- |
| 10392 |
struct AACallEdgesImpl : public AACallEdges { |
--- |
10392 |
struct AACallEdgesImpl : public AACallEdges { |
--- |
| 10393 |
AACallEdgesImpl(const IRPosition &IRP, Attributor &A) : AACallEdges(IRP, A) {} |
0 |
10393 |
AACallEdgesImpl(const IRPosition &IRP, Attributor &A) : AACallEdges(IRP, A) {} |
0 |
| 10394 |
|
--- |
10394 |
|
--- |
| 10395 |
const SetVector &getOptimisticEdges() const override { |
0 |
10395 |
const SetVector &getOptimisticEdges() const override { |
0 |
| 10396 |
return CalledFunctions; |
0 |
10396 |
return CalledFunctions; |
0 |
| 10397 |
} |
--- |
10397 |
} |
--- |
| 10398 |
|
--- |
10398 |
|
--- |
| 10399 |
bool hasUnknownCallee() const override { return HasUnknownCallee; } |
0 |
10399 |
bool hasUnknownCallee() const override { return HasUnknownCallee; } |
0 |
| 10400 |
|
--- |
10400 |
|
--- |
| 10401 |
bool hasNonAsmUnknownCallee() const override { |
0 |
10401 |
bool hasNonAsmUnknownCallee() const override { |
0 |
| 10402 |
return HasUnknownCalleeNonAsm; |
0 |
10402 |
return HasUnknownCalleeNonAsm; |
0 |
| 10403 |
} |
--- |
10403 |
} |
--- |
| 10404 |
|
--- |
10404 |
|
--- |
| 10405 |
const std::string getAsStr(Attributor *A) const override { |
0 |
10405 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 10406 |
return "CallEdges[" + std::to_string(HasUnknownCallee) + "," + |
0 |
10406 |
return "CallEdges[" + std::to_string(HasUnknownCallee) + "," + |
0 |
| 10407 |
std::to_string(CalledFunctions.size()) + "]"; |
0 |
10407 |
std::to_string(CalledFunctions.size()) + "]"; |
0 |
| 10408 |
} |
--- |
10408 |
} |
--- |
| 10409 |
|
--- |
10409 |
|
--- |
| 10410 |
void trackStatistics() const override {} |
0 |
10410 |
void trackStatistics() const override {} |
0 |
| 10411 |
|
--- |
10411 |
|
--- |
| 10412 |
protected: |
--- |
10412 |
protected: |
--- |
| 10413 |
void addCalledFunction(Function *Fn, ChangeStatus &Change) { |
0 |
10413 |
void addCalledFunction(Function *Fn, ChangeStatus &Change) { |
0 |
| 10414 |
if (CalledFunctions.insert(Fn)) { |
0 |
10414 |
if (CalledFunctions.insert(Fn)) { |
0 |
| 10415 |
Change = ChangeStatus::CHANGED; |
0 |
10415 |
Change = ChangeStatus::CHANGED; |
0 |
| 10416 |
LLVM_DEBUG(dbgs() << "[AACallEdges] New call edge: " << Fn->getName() |
0 |
10416 |
LLVM_DEBUG(dbgs() << "[AACallEdges] New call edge: " << Fn->getName() |
0 |
| 10417 |
<< "\n"); |
--- |
10417 |
<< "\n"); |
--- |
| 10418 |
} |
--- |
10418 |
} |
--- |
| 10419 |
} |
0 |
10419 |
} |
0 |
| 10420 |
|
--- |
10420 |
|
--- |
| 10421 |
void setHasUnknownCallee(bool NonAsm, ChangeStatus &Change) { |
0 |
10421 |
void setHasUnknownCallee(bool NonAsm, ChangeStatus &Change) { |
0 |
| 10422 |
if (!HasUnknownCallee) |
0 |
10422 |
if (!HasUnknownCallee) |
0 |
| 10423 |
Change = ChangeStatus::CHANGED; |
0 |
10423 |
Change = ChangeStatus::CHANGED; |
0 |
| 10424 |
if (NonAsm && !HasUnknownCalleeNonAsm) |
0 |
10424 |
if (NonAsm && !HasUnknownCalleeNonAsm) |
0 |
| 10425 |
Change = ChangeStatus::CHANGED; |
0 |
10425 |
Change = ChangeStatus::CHANGED; |
0 |
| 10426 |
HasUnknownCalleeNonAsm |= NonAsm; |
0 |
10426 |
HasUnknownCalleeNonAsm |= NonAsm; |
0 |
| 10427 |
HasUnknownCallee = true; |
0 |
10427 |
HasUnknownCallee = true; |
0 |
| 10428 |
} |
0 |
10428 |
} |
0 |
| 10429 |
|
--- |
10429 |
|
--- |
| 10430 |
private: |
--- |
10430 |
private: |
--- |
| 10431 |
/// Optimistic set of functions that might be called by this position. |
--- |
10431 |
/// Optimistic set of functions that might be called by this position. |
--- |
| 10432 |
SetVector CalledFunctions; |
--- |
10432 |
SetVector CalledFunctions; |
--- |
| 10433 |
|
--- |
10433 |
|
--- |
| 10434 |
/// Is there any call with a unknown callee. |
--- |
10434 |
/// Is there any call with a unknown callee. |
--- |
| 10435 |
bool HasUnknownCallee = false; |
--- |
10435 |
bool HasUnknownCallee = false; |
--- |
| 10436 |
|
--- |
10436 |
|
--- |
| 10437 |
/// Is there any call with a unknown callee, excluding any inline asm. |
--- |
10437 |
/// Is there any call with a unknown callee, excluding any inline asm. |
--- |
| 10438 |
bool HasUnknownCalleeNonAsm = false; |
--- |
10438 |
bool HasUnknownCalleeNonAsm = false; |
--- |
| 10439 |
}; |
--- |
10439 |
}; |
--- |
| 10440 |
|
--- |
10440 |
|
--- |
| 10441 |
struct AACallEdgesCallSite : public AACallEdgesImpl { |
--- |
10441 |
struct AACallEdgesCallSite : public AACallEdgesImpl { |
--- |
| 10442 |
AACallEdgesCallSite(const IRPosition &IRP, Attributor &A) |
0 |
10442 |
AACallEdgesCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 10443 |
: AACallEdgesImpl(IRP, A) {} |
0 |
10443 |
: AACallEdgesImpl(IRP, A) {} |
0 |
| 10444 |
/// See AbstractAttribute::updateImpl(...). |
--- |
10444 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 10445 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
10445 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 10446 |
ChangeStatus Change = ChangeStatus::UNCHANGED; |
0 |
10446 |
ChangeStatus Change = ChangeStatus::UNCHANGED; |
0 |
| 10447 |
|
--- |
10447 |
|
--- |
| 10448 |
auto VisitValue = [&](Value &V, const Instruction *CtxI) -> bool { |
0 |
10448 |
auto VisitValue = [&](Value &V, const Instruction *CtxI) -> bool { |
0 |
| 10449 |
if (Function *Fn = dyn_cast(&V)) { |
0 |
10449 |
if (Function *Fn = dyn_cast(&V)) { |
0 |
| 10450 |
addCalledFunction(Fn, Change); |
0 |
10450 |
addCalledFunction(Fn, Change); |
0 |
| 10451 |
} else { |
--- |
10451 |
} else { |
--- |
| 10452 |
LLVM_DEBUG(dbgs() << "[AACallEdges] Unrecognized value: " << V << "\n"); |
0 |
10452 |
LLVM_DEBUG(dbgs() << "[AACallEdges] Unrecognized value: " << V << "\n"); |
0 |
| 10453 |
setHasUnknownCallee(true, Change); |
0 |
10453 |
setHasUnknownCallee(true, Change); |
0 |
| 10454 |
} |
--- |
10454 |
} |
--- |
| 10455 |
|
--- |
10455 |
|
--- |
| 10456 |
// Explore all values. |
--- |
10456 |
// Explore all values. |
--- |
| 10457 |
return true; |
0 |
10457 |
return true; |
0 |
| 10458 |
}; |
0 |
10458 |
}; |
0 |
| 10459 |
|
--- |
10459 |
|
--- |
| 10460 |
SmallVector Values; |
0 |
10460 |
SmallVector Values; |
0 |
| 10461 |
// Process any value that we might call. |
--- |
10461 |
// Process any value that we might call. |
--- |
| 10462 |
auto ProcessCalledOperand = [&](Value *V, Instruction *CtxI) { |
0 |
10462 |
auto ProcessCalledOperand = [&](Value *V, Instruction *CtxI) { |
0 |
| 10463 |
if (isa(V)) { |
0 |
10463 |
if (isa(V)) { |
0 |
| 10464 |
VisitValue(*V, CtxI); |
0 |
10464 |
VisitValue(*V, CtxI); |
0 |
| 10465 |
return; |
0 |
10465 |
return; |
0 |
| 10466 |
} |
--- |
10466 |
} |
--- |
| 10467 |
|
--- |
10467 |
|
--- |
| 10468 |
bool UsedAssumedInformation = false; |
0 |
10468 |
bool UsedAssumedInformation = false; |
0 |
| 10469 |
Values.clear(); |
0 |
10469 |
Values.clear(); |
0 |
| 10470 |
if (!A.getAssumedSimplifiedValues(IRPosition::value(*V), *this, Values, |
0 |
10470 |
if (!A.getAssumedSimplifiedValues(IRPosition::value(*V), *this, Values, |
0 |
| 10471 |
AA::AnyScope, UsedAssumedInformation)) { |
--- |
10471 |
AA::AnyScope, UsedAssumedInformation)) { |
--- |
| 10472 |
Values.push_back({*V, CtxI}); |
0 |
10472 |
Values.push_back({*V, CtxI}); |
0 |
| 10473 |
} |
--- |
10473 |
} |
--- |
| 10474 |
for (auto &VAC : Values) |
0 |
10474 |
for (auto &VAC : Values) |
0 |
| 10475 |
VisitValue(*VAC.getValue(), VAC.getCtxI()); |
0 |
10475 |
VisitValue(*VAC.getValue(), VAC.getCtxI()); |
0 |
| 10476 |
}; |
0 |
10476 |
}; |
0 |
| 10477 |
|
--- |
10477 |
|
--- |
| 10478 |
CallBase *CB = cast(getCtxI()); |
0 |
10478 |
CallBase *CB = cast(getCtxI()); |
0 |
| 10479 |
|
--- |
10479 |
|
--- |
| 10480 |
if (auto *IA = dyn_cast(CB->getCalledOperand())) { |
0 |
10480 |
if (auto *IA = dyn_cast(CB->getCalledOperand())) { |
0 |
| 10481 |
if (IA->hasSideEffects() && |
0 |
10481 |
if (IA->hasSideEffects() && |
0 |
| 10482 |
!hasAssumption(*CB->getCaller(), "ompx_no_call_asm") && |
0 |
10482 |
!hasAssumption(*CB->getCaller(), "ompx_no_call_asm") && |
0 |
| 10483 |
!hasAssumption(*CB, "ompx_no_call_asm")) { |
0 |
10483 |
!hasAssumption(*CB, "ompx_no_call_asm")) { |
0 |
| 10484 |
setHasUnknownCallee(false, Change); |
0 |
10484 |
setHasUnknownCallee(false, Change); |
0 |
| 10485 |
} |
--- |
10485 |
} |
--- |
| 10486 |
return Change; |
0 |
10486 |
return Change; |
0 |
| 10487 |
} |
--- |
10487 |
} |
--- |
| 10488 |
|
--- |
10488 |
|
--- |
| 10489 |
// Process callee metadata if available. |
--- |
10489 |
// Process callee metadata if available. |
--- |
| 10490 |
if (auto *MD = getCtxI()->getMetadata(LLVMContext::MD_callees)) { |
0 |
10490 |
if (auto *MD = getCtxI()->getMetadata(LLVMContext::MD_callees)) { |
0 |
| 10491 |
for (const auto &Op : MD->operands()) { |
0 |
10491 |
for (const auto &Op : MD->operands()) { |
0 |
| 10492 |
Function *Callee = mdconst::dyn_extract_or_null(Op); |
0 |
10492 |
Function *Callee = mdconst::dyn_extract_or_null(Op); |
0 |
| 10493 |
if (Callee) |
0 |
10493 |
if (Callee) |
0 |
| 10494 |
addCalledFunction(Callee, Change); |
0 |
10494 |
addCalledFunction(Callee, Change); |
0 |
| 10495 |
} |
--- |
10495 |
} |
--- |
| 10496 |
return Change; |
0 |
10496 |
return Change; |
0 |
| 10497 |
} |
--- |
10497 |
} |
--- |
| 10498 |
|
--- |
10498 |
|
--- |
| 10499 |
// The most simple case. |
--- |
10499 |
// The most simple case. |
--- |
| 10500 |
ProcessCalledOperand(CB->getCalledOperand(), CB); |
0 |
10500 |
ProcessCalledOperand(CB->getCalledOperand(), CB); |
0 |
| 10501 |
|
--- |
10501 |
|
--- |
| 10502 |
// Process callback functions. |
--- |
10502 |
// Process callback functions. |
--- |
| 10503 |
SmallVector CallbackUses; |
0 |
10503 |
SmallVector CallbackUses; |
0 |
| 10504 |
AbstractCallSite::getCallbackUses(*CB, CallbackUses); |
0 |
10504 |
AbstractCallSite::getCallbackUses(*CB, CallbackUses); |
0 |
| 10505 |
for (const Use *U : CallbackUses) |
0 |
10505 |
for (const Use *U : CallbackUses) |
0 |
| 10506 |
ProcessCalledOperand(U->get(), CB); |
0 |
10506 |
ProcessCalledOperand(U->get(), CB); |
0 |
| 10507 |
|
--- |
10507 |
|
--- |
| 10508 |
return Change; |
0 |
10508 |
return Change; |
0 |
| 10509 |
} |
0 |
10509 |
} |
0 |
| 10510 |
}; |
--- |
10510 |
}; |
--- |
| 10511 |
|
--- |
10511 |
|
--- |
| 10512 |
struct AACallEdgesFunction : public AACallEdgesImpl { |
--- |
10512 |
struct AACallEdgesFunction : public AACallEdgesImpl { |
--- |
| 10513 |
AACallEdgesFunction(const IRPosition &IRP, Attributor &A) |
0 |
10513 |
AACallEdgesFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 10514 |
: AACallEdgesImpl(IRP, A) {} |
0 |
10514 |
: AACallEdgesImpl(IRP, A) {} |
0 |
| 10515 |
|
--- |
10515 |
|
--- |
| 10516 |
/// See AbstractAttribute::updateImpl(...). |
--- |
10516 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 10517 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
10517 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 10518 |
ChangeStatus Change = ChangeStatus::UNCHANGED; |
0 |
10518 |
ChangeStatus Change = ChangeStatus::UNCHANGED; |
0 |
| 10519 |
|
--- |
10519 |
|
--- |
| 10520 |
auto ProcessCallInst = [&](Instruction &Inst) { |
0 |
10520 |
auto ProcessCallInst = [&](Instruction &Inst) { |
0 |
| 10521 |
CallBase &CB = cast(Inst); |
0 |
10521 |
CallBase &CB = cast(Inst); |
0 |
| 10522 |
|
--- |
10522 |
|
--- |
| 10523 |
auto *CBEdges = A.getAAFor( |
0 |
10523 |
auto *CBEdges = A.getAAFor( |
0 |
| 10524 |
*this, IRPosition::callsite_function(CB), DepClassTy::REQUIRED); |
0 |
10524 |
*this, IRPosition::callsite_function(CB), DepClassTy::REQUIRED); |
0 |
| 10525 |
if (!CBEdges) |
0 |
10525 |
if (!CBEdges) |
0 |
| 10526 |
return false; |
0 |
10526 |
return false; |
0 |
| 10527 |
if (CBEdges->hasNonAsmUnknownCallee()) |
0 |
10527 |
if (CBEdges->hasNonAsmUnknownCallee()) |
0 |
| 10528 |
setHasUnknownCallee(true, Change); |
0 |
10528 |
setHasUnknownCallee(true, Change); |
0 |
| 10529 |
if (CBEdges->hasUnknownCallee()) |
0 |
10529 |
if (CBEdges->hasUnknownCallee()) |
0 |
| 10530 |
setHasUnknownCallee(false, Change); |
0 |
10530 |
setHasUnknownCallee(false, Change); |
0 |
| 10531 |
|
--- |
10531 |
|
--- |
| 10532 |
for (Function *F : CBEdges->getOptimisticEdges()) |
0 |
10532 |
for (Function *F : CBEdges->getOptimisticEdges()) |
0 |
| 10533 |
addCalledFunction(F, Change); |
0 |
10533 |
addCalledFunction(F, Change); |
0 |
| 10534 |
|
--- |
10534 |
|
--- |
| 10535 |
return true; |
0 |
10535 |
return true; |
0 |
| 10536 |
}; |
0 |
10536 |
}; |
0 |
| 10537 |
|
--- |
10537 |
|
--- |
| 10538 |
// Visit all callable instructions. |
--- |
10538 |
// Visit all callable instructions. |
--- |
| 10539 |
bool UsedAssumedInformation = false; |
0 |
10539 |
bool UsedAssumedInformation = false; |
0 |
| 10540 |
if (!A.checkForAllCallLikeInstructions(ProcessCallInst, *this, |
0 |
10540 |
if (!A.checkForAllCallLikeInstructions(ProcessCallInst, *this, |
0 |
| 10541 |
UsedAssumedInformation, |
--- |
10541 |
UsedAssumedInformation, |
--- |
| 10542 |
/* CheckBBLivenessOnly */ true)) { |
--- |
10542 |
/* CheckBBLivenessOnly */ true)) { |
--- |
| 10543 |
// If we haven't looked at all call like instructions, assume that there |
--- |
10543 |
// If we haven't looked at all call like instructions, assume that there |
--- |
| 10544 |
// are unknown callees. |
--- |
10544 |
// are unknown callees. |
--- |
| 10545 |
setHasUnknownCallee(true, Change); |
0 |
10545 |
setHasUnknownCallee(true, Change); |
0 |
| 10546 |
} |
--- |
10546 |
} |
--- |
| 10547 |
|
--- |
10547 |
|
--- |
| 10548 |
return Change; |
0 |
10548 |
return Change; |
0 |
| 10549 |
} |
--- |
10549 |
} |
--- |
| 10550 |
}; |
--- |
10550 |
}; |
--- |
| 10551 |
|
--- |
10551 |
|
--- |
| 10552 |
/// -------------------AAInterFnReachability Attribute-------------------------- |
--- |
10552 |
/// -------------------AAInterFnReachability Attribute-------------------------- |
--- |
| 10553 |
|
--- |
10553 |
|
--- |
| 10554 |
struct AAInterFnReachabilityFunction |
--- |
10554 |
struct AAInterFnReachabilityFunction |
--- |
| 10555 |
: public CachedReachabilityAA { |
--- |
10555 |
: public CachedReachabilityAA { |
--- |
| 10556 |
using Base = CachedReachabilityAA; |
--- |
10556 |
using Base = CachedReachabilityAA; |
--- |
| 10557 |
AAInterFnReachabilityFunction(const IRPosition &IRP, Attributor &A) |
0 |
10557 |
AAInterFnReachabilityFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 10558 |
: Base(IRP, A) {} |
0 |
10558 |
: Base(IRP, A) {} |
0 |
| 10559 |
|
--- |
10559 |
|
--- |
| 10560 |
bool instructionCanReach( |
0 |
10560 |
bool instructionCanReach( |
0 |
| 10561 |
Attributor &A, const Instruction &From, const Function &To, |
--- |
10561 |
Attributor &A, const Instruction &From, const Function &To, |
--- |
| 10562 |
const AA::InstExclusionSetTy *ExclusionSet, |
--- |
10562 |
const AA::InstExclusionSetTy *ExclusionSet, |
--- |
| 10563 |
SmallPtrSet *Visited) const override { |
--- |
10563 |
SmallPtrSet *Visited) const override { |
--- |
| 10564 |
assert(From.getFunction() == getAnchorScope() && "Queried the wrong AA!"); |
0 |
10564 |
assert(From.getFunction() == getAnchorScope() && "Queried the wrong AA!"); |
0 |
| 10565 |
auto *NonConstThis = const_cast(this); |
0 |
10565 |
auto *NonConstThis = const_cast(this); |
0 |
| 10566 |
|
--- |
10566 |
|
--- |
| 10567 |
RQITy StackRQI(A, From, To, ExclusionSet, false); |
0 |
10567 |
RQITy StackRQI(A, From, To, ExclusionSet, false); |
0 |
| 10568 |
typename RQITy::Reachable Result; |
--- |
10568 |
typename RQITy::Reachable Result; |
--- |
| 10569 |
if (!NonConstThis->checkQueryCache(A, StackRQI, Result)) |
0 |
10569 |
if (!NonConstThis->checkQueryCache(A, StackRQI, Result)) |
0 |
| 10570 |
return NonConstThis->isReachableImpl(A, StackRQI); |
0 |
10570 |
return NonConstThis->isReachableImpl(A, StackRQI); |
0 |
| 10571 |
return Result == RQITy::Reachable::Yes; |
0 |
10571 |
return Result == RQITy::Reachable::Yes; |
0 |
| 10572 |
} |
--- |
10572 |
} |
--- |
| 10573 |
|
--- |
10573 |
|
--- |
| 10574 |
bool isReachableImpl(Attributor &A, RQITy &RQI) override { |
0 |
10574 |
bool isReachableImpl(Attributor &A, RQITy &RQI) override { |
0 |
| 10575 |
return isReachableImpl(A, RQI, nullptr); |
0 |
10575 |
return isReachableImpl(A, RQI, nullptr); |
0 |
| 10576 |
} |
--- |
10576 |
} |
--- |
| 10577 |
|
--- |
10577 |
|
--- |
| 10578 |
bool isReachableImpl(Attributor &A, RQITy &RQI, |
0 |
10578 |
bool isReachableImpl(Attributor &A, RQITy &RQI, |
0 |
| 10579 |
SmallPtrSet *Visited) { |
--- |
10579 |
SmallPtrSet *Visited) { |
--- |
| 10580 |
|
--- |
10580 |
|
--- |
| 10581 |
SmallPtrSet LocalVisited; |
0 |
10581 |
SmallPtrSet LocalVisited; |
0 |
| 10582 |
if (!Visited) |
0 |
10582 |
if (!Visited) |
0 |
| 10583 |
Visited = &LocalVisited; |
0 |
10583 |
Visited = &LocalVisited; |
0 |
| 10584 |
|
--- |
10584 |
|
--- |
| 10585 |
auto CheckReachableCallBase = [&](CallBase *CB) { |
0 |
10585 |
auto CheckReachableCallBase = [&](CallBase *CB) { |
0 |
| 10586 |
auto *CBEdges = A.getAAFor( |
0 |
10586 |
auto *CBEdges = A.getAAFor( |
0 |
| 10587 |
*this, IRPosition::callsite_function(*CB), DepClassTy::OPTIONAL); |
0 |
10587 |
*this, IRPosition::callsite_function(*CB), DepClassTy::OPTIONAL); |
0 |
| 10588 |
if (!CBEdges || !CBEdges->getState().isValidState()) |
0 |
10588 |
if (!CBEdges || !CBEdges->getState().isValidState()) |
0 |
| 10589 |
return false; |
0 |
10589 |
return false; |
0 |
| 10590 |
// TODO Check To backwards in this case. |
--- |
10590 |
// TODO Check To backwards in this case. |
--- |
| 10591 |
if (CBEdges->hasUnknownCallee()) |
0 |
10591 |
if (CBEdges->hasUnknownCallee()) |
0 |
| 10592 |
return false; |
0 |
10592 |
return false; |
0 |
| 10593 |
|
--- |
10593 |
|
--- |
| 10594 |
for (Function *Fn : CBEdges->getOptimisticEdges()) { |
0 |
10594 |
for (Function *Fn : CBEdges->getOptimisticEdges()) { |
0 |
| 10595 |
if (Fn == RQI.To) |
0 |
10595 |
if (Fn == RQI.To) |
0 |
| 10596 |
return false; |
0 |
10596 |
return false; |
0 |
| 10597 |
if (!Visited->insert(Fn).second) |
0 |
10597 |
if (!Visited->insert(Fn).second) |
0 |
| 10598 |
continue; |
0 |
10598 |
continue; |
0 |
| 10599 |
if (Fn->isDeclaration()) { |
0 |
10599 |
if (Fn->isDeclaration()) { |
0 |
| 10600 |
if (Fn->hasFnAttribute(Attribute::NoCallback)) |
0 |
10600 |
if (Fn->hasFnAttribute(Attribute::NoCallback)) |
0 |
| 10601 |
continue; |
0 |
10601 |
continue; |
0 |
| 10602 |
// TODO Check To backwards in this case. |
--- |
10602 |
// TODO Check To backwards in this case. |
--- |
| 10603 |
return false; |
0 |
10603 |
return false; |
0 |
| 10604 |
} |
--- |
10604 |
} |
--- |
| 10605 |
|
--- |
10605 |
|
--- |
| 10606 |
const AAInterFnReachability *InterFnReachability = this; |
0 |
10606 |
const AAInterFnReachability *InterFnReachability = this; |
0 |
| 10607 |
if (Fn != getAnchorScope()) |
0 |
10607 |
if (Fn != getAnchorScope()) |
0 |
| 10608 |
InterFnReachability = A.getAAFor( |
0 |
10608 |
InterFnReachability = A.getAAFor( |
0 |
| 10609 |
*this, IRPosition::function(*Fn), DepClassTy::OPTIONAL); |
0 |
10609 |
*this, IRPosition::function(*Fn), DepClassTy::OPTIONAL); |
0 |
| 10610 |
|
--- |
10610 |
|
--- |
| 10611 |
const Instruction &FnFirstInst = Fn->getEntryBlock().front(); |
0 |
10611 |
const Instruction &FnFirstInst = Fn->getEntryBlock().front(); |
0 |
| 10612 |
if (!InterFnReachability || |
0 |
10612 |
if (!InterFnReachability || |
0 |
| 10613 |
InterFnReachability->instructionCanReach(A, FnFirstInst, *RQI.To, |
0 |
10613 |
InterFnReachability->instructionCanReach(A, FnFirstInst, *RQI.To, |
0 |
| 10614 |
RQI.ExclusionSet, Visited)) |
--- |
10614 |
RQI.ExclusionSet, Visited)) |
--- |
| 10615 |
return false; |
0 |
10615 |
return false; |
0 |
| 10616 |
} |
--- |
10616 |
} |
--- |
| 10617 |
return true; |
0 |
10617 |
return true; |
0 |
| 10618 |
}; |
0 |
10618 |
}; |
0 |
| 10619 |
|
--- |
10619 |
|
--- |
| 10620 |
const auto *IntraFnReachability = A.getAAFor( |
0 |
10620 |
const auto *IntraFnReachability = A.getAAFor( |
0 |
| 10621 |
*this, IRPosition::function(*RQI.From->getFunction()), |
0 |
10621 |
*this, IRPosition::function(*RQI.From->getFunction()), |
0 |
| 10622 |
DepClassTy::OPTIONAL); |
0 |
10622 |
DepClassTy::OPTIONAL); |
0 |
| 10623 |
|
--- |
10623 |
|
--- |
| 10624 |
// Determine call like instructions that we can reach from the inst. |
--- |
10624 |
// Determine call like instructions that we can reach from the inst. |
--- |
| 10625 |
auto CheckCallBase = [&](Instruction &CBInst) { |
0 |
10625 |
auto CheckCallBase = [&](Instruction &CBInst) { |
0 |
| 10626 |
// There are usually less nodes in the call graph, check inter function |
--- |
10626 |
// There are usually less nodes in the call graph, check inter function |
--- |
| 10627 |
// reachability first. |
--- |
10627 |
// reachability first. |
--- |
| 10628 |
if (CheckReachableCallBase(cast(&CBInst))) |
0 |
10628 |
if (CheckReachableCallBase(cast(&CBInst))) |
0 |
| 10629 |
return true; |
0 |
10629 |
return true; |
0 |
| 10630 |
return IntraFnReachability && !IntraFnReachability->isAssumedReachable( |
0 |
10630 |
return IntraFnReachability && !IntraFnReachability->isAssumedReachable( |
0 |
| 10631 |
A, *RQI.From, CBInst, RQI.ExclusionSet); |
0 |
10631 |
A, *RQI.From, CBInst, RQI.ExclusionSet); |
0 |
| 10632 |
}; |
0 |
10632 |
}; |
0 |
| 10633 |
|
--- |
10633 |
|
--- |
| 10634 |
bool UsedExclusionSet = /* conservative */ true; |
0 |
10634 |
bool UsedExclusionSet = /* conservative */ true; |
0 |
| 10635 |
bool UsedAssumedInformation = false; |
0 |
10635 |
bool UsedAssumedInformation = false; |
0 |
| 10636 |
if (!A.checkForAllCallLikeInstructions(CheckCallBase, *this, |
0 |
10636 |
if (!A.checkForAllCallLikeInstructions(CheckCallBase, *this, |
0 |
| 10637 |
UsedAssumedInformation, |
--- |
10637 |
UsedAssumedInformation, |
--- |
| 10638 |
/* CheckBBLivenessOnly */ true)) |
--- |
10638 |
/* CheckBBLivenessOnly */ true)) |
--- |
| 10639 |
return rememberResult(A, RQITy::Reachable::Yes, RQI, UsedExclusionSet); |
0 |
10639 |
return rememberResult(A, RQITy::Reachable::Yes, RQI, UsedExclusionSet); |
0 |
| 10640 |
|
--- |
10640 |
|
--- |
| 10641 |
return rememberResult(A, RQITy::Reachable::No, RQI, UsedExclusionSet); |
0 |
10641 |
return rememberResult(A, RQITy::Reachable::No, RQI, UsedExclusionSet); |
0 |
| 10642 |
} |
0 |
10642 |
} |
0 |
| 10643 |
|
--- |
10643 |
|
--- |
| 10644 |
void trackStatistics() const override {} |
0 |
10644 |
void trackStatistics() const override {} |
0 |
| 10645 |
}; |
--- |
10645 |
}; |
--- |
| 10646 |
} // namespace |
--- |
10646 |
} // namespace |
--- |
| 10647 |
|
--- |
10647 |
|
--- |
| 10648 |
template |
--- |
10648 |
template |
--- |
| 10649 |
static std::optional |
--- |
10649 |
static std::optional |
--- |
| 10650 |
askForAssumedConstant(Attributor &A, const AbstractAttribute &QueryingAA, |
0 |
10650 |
askForAssumedConstant(Attributor &A, const AbstractAttribute &QueryingAA, |
0 |
| 10651 |
const IRPosition &IRP, Type &Ty) { |
--- |
10651 |
const IRPosition &IRP, Type &Ty) { |
--- |
| 10652 |
if (!Ty.isIntegerTy()) |
0 |
10652 |
if (!Ty.isIntegerTy()) |
0 |
| 10653 |
return nullptr; |
0 |
10653 |
return nullptr; |
0 |
| 10654 |
|
--- |
10654 |
|
--- |
| 10655 |
// This will also pass the call base context. |
--- |
10655 |
// This will also pass the call base context. |
--- |
| 10656 |
const auto *AA = A.getAAFor(QueryingAA, IRP, DepClassTy::NONE); |
0 |
10656 |
const auto *AA = A.getAAFor(QueryingAA, IRP, DepClassTy::NONE); |
0 |
| 10657 |
if (!AA) |
0 |
10657 |
if (!AA) |
0 |
| 10658 |
return nullptr; |
0 |
10658 |
return nullptr; |
0 |
| 10659 |
|
--- |
10659 |
|
--- |
| 10660 |
std::optional COpt = AA->getAssumedConstant(A); |
0 |
10660 |
std::optional COpt = AA->getAssumedConstant(A); |
0 |
| 10661 |
|
--- |
10661 |
|
--- |
| 10662 |
if (!COpt.has_value()) { |
0 |
10662 |
if (!COpt.has_value()) { |
0 |
| 10663 |
A.recordDependence(*AA, QueryingAA, DepClassTy::OPTIONAL); |
0 |
10663 |
A.recordDependence(*AA, QueryingAA, DepClassTy::OPTIONAL); |
0 |
| 10664 |
return std::nullopt; |
0 |
10664 |
return std::nullopt; |
0 |
| 10665 |
} |
--- |
10665 |
} |
--- |
| 10666 |
if (auto *C = *COpt) { |
0 |
10666 |
if (auto *C = *COpt) { |
0 |
| 10667 |
A.recordDependence(*AA, QueryingAA, DepClassTy::OPTIONAL); |
0 |
10667 |
A.recordDependence(*AA, QueryingAA, DepClassTy::OPTIONAL); |
0 |
| 10668 |
return C; |
0 |
10668 |
return C; |
0 |
| 10669 |
} |
--- |
10669 |
} |
--- |
| 10670 |
return nullptr; |
0 |
10670 |
return nullptr; |
0 |
| 10671 |
} |
--- |
10671 |
} |
--- |
| 10672 |
|
--- |
10672 |
|
--- |
| 10673 |
Value *AAPotentialValues::getSingleValue( |
0 |
10673 |
Value *AAPotentialValues::getSingleValue( |
0 |
| 10674 |
Attributor &A, const AbstractAttribute &AA, const IRPosition &IRP, |
--- |
10674 |
Attributor &A, const AbstractAttribute &AA, const IRPosition &IRP, |
--- |
| 10675 |
SmallVectorImpl &Values) { |
--- |
10675 |
SmallVectorImpl &Values) { |
--- |
| 10676 |
Type &Ty = *IRP.getAssociatedType(); |
0 |
10676 |
Type &Ty = *IRP.getAssociatedType(); |
0 |
| 10677 |
std::optional V; |
0 |
10677 |
std::optional V; |
0 |
| 10678 |
for (auto &It : Values) { |
0 |
10678 |
for (auto &It : Values) { |
0 |
| 10679 |
V = AA::combineOptionalValuesInAAValueLatice(V, It.getValue(), &Ty); |
0 |
10679 |
V = AA::combineOptionalValuesInAAValueLatice(V, It.getValue(), &Ty); |
0 |
| 10680 |
if (V.has_value() && !*V) |
0 |
10680 |
if (V.has_value() && !*V) |
0 |
| 10681 |
break; |
0 |
10681 |
break; |
0 |
| 10682 |
} |
--- |
10682 |
} |
--- |
| 10683 |
if (!V.has_value()) |
0 |
10683 |
if (!V.has_value()) |
0 |
| 10684 |
return UndefValue::get(&Ty); |
0 |
10684 |
return UndefValue::get(&Ty); |
0 |
| 10685 |
return *V; |
0 |
10685 |
return *V; |
0 |
| 10686 |
} |
--- |
10686 |
} |
--- |
| 10687 |
|
--- |
10687 |
|
--- |
| 10688 |
namespace { |
--- |
10688 |
namespace { |
--- |
| 10689 |
struct AAPotentialValuesImpl : AAPotentialValues { |
--- |
10689 |
struct AAPotentialValuesImpl : AAPotentialValues { |
--- |
| 10690 |
using StateType = PotentialLLVMValuesState; |
--- |
10690 |
using StateType = PotentialLLVMValuesState; |
--- |
| 10691 |
|
--- |
10691 |
|
--- |
| 10692 |
AAPotentialValuesImpl(const IRPosition &IRP, Attributor &A) |
0 |
10692 |
AAPotentialValuesImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 10693 |
: AAPotentialValues(IRP, A) {} |
0 |
10693 |
: AAPotentialValues(IRP, A) {} |
0 |
| 10694 |
|
--- |
10694 |
|
--- |
| 10695 |
/// See AbstractAttribute::initialize(..). |
--- |
10695 |
/// See AbstractAttribute::initialize(..). |
--- |
| 10696 |
void initialize(Attributor &A) override { |
0 |
10696 |
void initialize(Attributor &A) override { |
0 |
| 10697 |
if (A.hasSimplificationCallback(getIRPosition())) { |
0 |
10697 |
if (A.hasSimplificationCallback(getIRPosition())) { |
0 |
| 10698 |
indicatePessimisticFixpoint(); |
0 |
10698 |
indicatePessimisticFixpoint(); |
0 |
| 10699 |
return; |
0 |
10699 |
return; |
0 |
| 10700 |
} |
--- |
10700 |
} |
--- |
| 10701 |
Value *Stripped = getAssociatedValue().stripPointerCasts(); |
0 |
10701 |
Value *Stripped = getAssociatedValue().stripPointerCasts(); |
0 |
| 10702 |
auto *CE = dyn_cast(Stripped); |
0 |
10702 |
auto *CE = dyn_cast(Stripped); |
0 |
| 10703 |
if (isa(Stripped) && |
0 |
10703 |
if (isa(Stripped) && |
0 |
| 10704 |
(!CE || CE->getOpcode() != Instruction::ICmp)) { |
0 |
10704 |
(!CE || CE->getOpcode() != Instruction::ICmp)) { |
0 |
| 10705 |
addValue(A, getState(), *Stripped, getCtxI(), AA::AnyScope, |
0 |
10705 |
addValue(A, getState(), *Stripped, getCtxI(), AA::AnyScope, |
0 |
| 10706 |
getAnchorScope()); |
--- |
10706 |
getAnchorScope()); |
--- |
| 10707 |
indicateOptimisticFixpoint(); |
0 |
10707 |
indicateOptimisticFixpoint(); |
0 |
| 10708 |
return; |
0 |
10708 |
return; |
0 |
| 10709 |
} |
--- |
10709 |
} |
--- |
| 10710 |
AAPotentialValues::initialize(A); |
0 |
10710 |
AAPotentialValues::initialize(A); |
0 |
| 10711 |
} |
--- |
10711 |
} |
--- |
| 10712 |
|
--- |
10712 |
|
--- |
| 10713 |
/// See AbstractAttribute::getAsStr(). |
--- |
10713 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 10714 |
const std::string getAsStr(Attributor *A) const override { |
0 |
10714 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 10715 |
std::string Str; |
0 |
10715 |
std::string Str; |
0 |
| 10716 |
llvm::raw_string_ostream OS(Str); |
0 |
10716 |
llvm::raw_string_ostream OS(Str); |
0 |
| 10717 |
OS << getState(); |
0 |
10717 |
OS << getState(); |
0 |
| 10718 |
return OS.str(); |
0 |
10718 |
return OS.str(); |
0 |
| 10719 |
} |
0 |
10719 |
} |
0 |
| 10720 |
|
--- |
10720 |
|
--- |
| 10721 |
template |
--- |
10721 |
template |
--- |
| 10722 |
static std::optional askOtherAA(Attributor &A, |
0 |
10722 |
static std::optional askOtherAA(Attributor &A, |
0 |
| 10723 |
const AbstractAttribute &AA, |
--- |
10723 |
const AbstractAttribute &AA, |
--- |
| 10724 |
const IRPosition &IRP, Type &Ty) { |
--- |
10724 |
const IRPosition &IRP, Type &Ty) { |
--- |
| 10725 |
if (isa(IRP.getAssociatedValue())) |
0 |
10725 |
if (isa(IRP.getAssociatedValue())) |
0 |
| 10726 |
return &IRP.getAssociatedValue(); |
0 |
10726 |
return &IRP.getAssociatedValue(); |
0 |
| 10727 |
std::optional C = askForAssumedConstant(A, AA, IRP, Ty); |
0 |
10727 |
std::optional C = askForAssumedConstant(A, AA, IRP, Ty); |
0 |
| 10728 |
if (!C) |
0 |
10728 |
if (!C) |
0 |
| 10729 |
return std::nullopt; |
0 |
10729 |
return std::nullopt; |
0 |
| 10730 |
if (*C) |
0 |
10730 |
if (*C) |
0 |
| 10731 |
if (auto *CC = AA::getWithType(**C, Ty)) |
0 |
10731 |
if (auto *CC = AA::getWithType(**C, Ty)) |
0 |
| 10732 |
return CC; |
0 |
10732 |
return CC; |
0 |
| 10733 |
return nullptr; |
0 |
10733 |
return nullptr; |
0 |
| 10734 |
} |
--- |
10734 |
} |
--- |
| 10735 |
|
--- |
10735 |
|
--- |
| 10736 |
virtual void addValue(Attributor &A, StateType &State, Value &V, |
0 |
10736 |
virtual void addValue(Attributor &A, StateType &State, Value &V, |
0 |
| 10737 |
const Instruction *CtxI, AA::ValueScope S, |
--- |
10737 |
const Instruction *CtxI, AA::ValueScope S, |
--- |
| 10738 |
Function *AnchorScope) const { |
--- |
10738 |
Function *AnchorScope) const { |
--- |
| 10739 |
|
--- |
10739 |
|
--- |
| 10740 |
IRPosition ValIRP = IRPosition::value(V); |
0 |
10740 |
IRPosition ValIRP = IRPosition::value(V); |
0 |
| 10741 |
if (auto *CB = dyn_cast_or_null(CtxI)) { |
0 |
10741 |
if (auto *CB = dyn_cast_or_null(CtxI)) { |
0 |
| 10742 |
for (const auto &U : CB->args()) { |
0 |
10742 |
for (const auto &U : CB->args()) { |
0 |
| 10743 |
if (U.get() != &V) |
0 |
10743 |
if (U.get() != &V) |
0 |
| 10744 |
continue; |
0 |
10744 |
continue; |
0 |
| 10745 |
ValIRP = IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U)); |
0 |
10745 |
ValIRP = IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U)); |
0 |
| 10746 |
break; |
0 |
10746 |
break; |
0 |
| 10747 |
} |
--- |
10747 |
} |
--- |
| 10748 |
} |
--- |
10748 |
} |
--- |
| 10749 |
|
--- |
10749 |
|
--- |
| 10750 |
Value *VPtr = &V; |
0 |
10750 |
Value *VPtr = &V; |
0 |
| 10751 |
if (ValIRP.getAssociatedType()->isIntegerTy()) { |
0 |
10751 |
if (ValIRP.getAssociatedType()->isIntegerTy()) { |
0 |
| 10752 |
Type &Ty = *getAssociatedType(); |
0 |
10752 |
Type &Ty = *getAssociatedType(); |
0 |
| 10753 |
std::optional SimpleV = |
--- |
10753 |
std::optional SimpleV = |
--- |
| 10754 |
askOtherAA(A, *this, ValIRP, Ty); |
0 |
10754 |
askOtherAA(A, *this, ValIRP, Ty); |
0 |
| 10755 |
if (SimpleV.has_value() && !*SimpleV) { |
0 |
10755 |
if (SimpleV.has_value() && !*SimpleV) { |
0 |
| 10756 |
auto *PotentialConstantsAA = A.getAAFor( |
0 |
10756 |
auto *PotentialConstantsAA = A.getAAFor( |
0 |
| 10757 |
*this, ValIRP, DepClassTy::OPTIONAL); |
--- |
10757 |
*this, ValIRP, DepClassTy::OPTIONAL); |
--- |
| 10758 |
if (PotentialConstantsAA && PotentialConstantsAA->isValidState()) { |
0 |
10758 |
if (PotentialConstantsAA && PotentialConstantsAA->isValidState()) { |
0 |
| 10759 |
for (const auto &It : PotentialConstantsAA->getAssumedSet()) |
0 |
10759 |
for (const auto &It : PotentialConstantsAA->getAssumedSet()) |
0 |
| 10760 |
State.unionAssumed({{*ConstantInt::get(&Ty, It), nullptr}, S}); |
0 |
10760 |
State.unionAssumed({{*ConstantInt::get(&Ty, It), nullptr}, S}); |
0 |
| 10761 |
if (PotentialConstantsAA->undefIsContained()) |
0 |
10761 |
if (PotentialConstantsAA->undefIsContained()) |
0 |
| 10762 |
State.unionAssumed({{*UndefValue::get(&Ty), nullptr}, S}); |
0 |
10762 |
State.unionAssumed({{*UndefValue::get(&Ty), nullptr}, S}); |
0 |
| 10763 |
return; |
0 |
10763 |
return; |
0 |
| 10764 |
} |
--- |
10764 |
} |
--- |
| 10765 |
} |
--- |
10765 |
} |
--- |
| 10766 |
if (!SimpleV.has_value()) |
0 |
10766 |
if (!SimpleV.has_value()) |
0 |
| 10767 |
return; |
0 |
10767 |
return; |
0 |
| 10768 |
|
--- |
10768 |
|
--- |
| 10769 |
if (*SimpleV) |
0 |
10769 |
if (*SimpleV) |
0 |
| 10770 |
VPtr = *SimpleV; |
0 |
10770 |
VPtr = *SimpleV; |
0 |
| 10771 |
} |
--- |
10771 |
} |
--- |
| 10772 |
|
--- |
10772 |
|
--- |
| 10773 |
if (isa(VPtr)) |
0 |
10773 |
if (isa(VPtr)) |
0 |
| 10774 |
CtxI = nullptr; |
0 |
10774 |
CtxI = nullptr; |
0 |
| 10775 |
if (!AA::isValidInScope(*VPtr, AnchorScope)) |
0 |
10775 |
if (!AA::isValidInScope(*VPtr, AnchorScope)) |
0 |
| 10776 |
S = AA::ValueScope(S | AA::Interprocedural); |
0 |
10776 |
S = AA::ValueScope(S | AA::Interprocedural); |
0 |
| 10777 |
|
--- |
10777 |
|
--- |
| 10778 |
State.unionAssumed({{*VPtr, CtxI}, S}); |
0 |
10778 |
State.unionAssumed({{*VPtr, CtxI}, S}); |
0 |
| 10779 |
} |
--- |
10779 |
} |
--- |
| 10780 |
|
--- |
10780 |
|
--- |
| 10781 |
/// Helper struct to tie a value+context pair together with the scope for |
--- |
10781 |
/// Helper struct to tie a value+context pair together with the scope for |
--- |
| 10782 |
/// which this is the simplified version. |
--- |
10782 |
/// which this is the simplified version. |
--- |
| 10783 |
struct ItemInfo { |
--- |
10783 |
struct ItemInfo { |
--- |
| 10784 |
AA::ValueAndContext I; |
--- |
10784 |
AA::ValueAndContext I; |
--- |
| 10785 |
AA::ValueScope S; |
--- |
10785 |
AA::ValueScope S; |
--- |
| 10786 |
|
--- |
10786 |
|
--- |
| 10787 |
bool operator==(const ItemInfo &II) const { |
0 |
10787 |
bool operator==(const ItemInfo &II) const { |
0 |
| 10788 |
return II.I == I && II.S == S; |
0 |
10788 |
return II.I == I && II.S == S; |
0 |
| 10789 |
}; |
--- |
10789 |
}; |
--- |
| 10790 |
bool operator<(const ItemInfo &II) const { |
0 |
10790 |
bool operator<(const ItemInfo &II) const { |
0 |
| 10791 |
if (I == II.I) |
0 |
10791 |
if (I == II.I) |
0 |
| 10792 |
return S < II.S; |
0 |
10792 |
return S < II.S; |
0 |
| 10793 |
return I < II.I; |
0 |
10793 |
return I < II.I; |
0 |
| 10794 |
}; |
--- |
10794 |
}; |
--- |
| 10795 |
}; |
--- |
10795 |
}; |
--- |
| 10796 |
|
--- |
10796 |
|
--- |
| 10797 |
bool recurseForValue(Attributor &A, const IRPosition &IRP, AA::ValueScope S) { |
0 |
10797 |
bool recurseForValue(Attributor &A, const IRPosition &IRP, AA::ValueScope S) { |
0 |
| 10798 |
SmallMapVector ValueScopeMap; |
0 |
10798 |
SmallMapVector ValueScopeMap; |
0 |
| 10799 |
for (auto CS : {AA::Intraprocedural, AA::Interprocedural}) { |
0 |
10799 |
for (auto CS : {AA::Intraprocedural, AA::Interprocedural}) { |
0 |
| 10800 |
if (!(CS & S)) |
0 |
10800 |
if (!(CS & S)) |
0 |
| 10801 |
continue; |
0 |
10801 |
continue; |
0 |
| 10802 |
|
--- |
10802 |
|
--- |
| 10803 |
bool UsedAssumedInformation = false; |
0 |
10803 |
bool UsedAssumedInformation = false; |
0 |
| 10804 |
SmallVector Values; |
0 |
10804 |
SmallVector Values; |
0 |
| 10805 |
if (!A.getAssumedSimplifiedValues(IRP, this, Values, CS, |
0 |
10805 |
if (!A.getAssumedSimplifiedValues(IRP, this, Values, CS, |
0 |
| 10806 |
UsedAssumedInformation)) |
--- |
10806 |
UsedAssumedInformation)) |
--- |
| 10807 |
return false; |
0 |
10807 |
return false; |
0 |
| 10808 |
|
--- |
10808 |
|
--- |
| 10809 |
for (auto &It : Values) |
0 |
10809 |
for (auto &It : Values) |
0 |
| 10810 |
ValueScopeMap[It] += CS; |
0 |
10810 |
ValueScopeMap[It] += CS; |
0 |
| 10811 |
} |
0 |
10811 |
} |
0 |
| 10812 |
for (auto &It : ValueScopeMap) |
0 |
10812 |
for (auto &It : ValueScopeMap) |
0 |
| 10813 |
addValue(A, getState(), *It.first.getValue(), It.first.getCtxI(), |
0 |
10813 |
addValue(A, getState(), *It.first.getValue(), It.first.getCtxI(), |
0 |
| 10814 |
AA::ValueScope(It.second), getAnchorScope()); |
0 |
10814 |
AA::ValueScope(It.second), getAnchorScope()); |
0 |
| 10815 |
|
--- |
10815 |
|
--- |
| 10816 |
return true; |
0 |
10816 |
return true; |
0 |
| 10817 |
} |
0 |
10817 |
} |
0 |
| 10818 |
|
--- |
10818 |
|
--- |
| 10819 |
void giveUpOnIntraprocedural(Attributor &A) { |
0 |
10819 |
void giveUpOnIntraprocedural(Attributor &A) { |
0 |
| 10820 |
auto NewS = StateType::getBestState(getState()); |
0 |
10820 |
auto NewS = StateType::getBestState(getState()); |
0 |
| 10821 |
for (const auto &It : getAssumedSet()) { |
0 |
10821 |
for (const auto &It : getAssumedSet()) { |
0 |
| 10822 |
if (It.second == AA::Intraprocedural) |
0 |
10822 |
if (It.second == AA::Intraprocedural) |
0 |
| 10823 |
continue; |
0 |
10823 |
continue; |
0 |
| 10824 |
addValue(A, NewS, *It.first.getValue(), It.first.getCtxI(), |
0 |
10824 |
addValue(A, NewS, *It.first.getValue(), It.first.getCtxI(), |
0 |
| 10825 |
AA::Interprocedural, getAnchorScope()); |
--- |
10825 |
AA::Interprocedural, getAnchorScope()); |
--- |
| 10826 |
} |
--- |
10826 |
} |
--- |
| 10827 |
assert(!undefIsContained() && "Undef should be an explicit value!"); |
0 |
10827 |
assert(!undefIsContained() && "Undef should be an explicit value!"); |
0 |
| 10828 |
addValue(A, NewS, getAssociatedValue(), getCtxI(), AA::Intraprocedural, |
0 |
10828 |
addValue(A, NewS, getAssociatedValue(), getCtxI(), AA::Intraprocedural, |
0 |
| 10829 |
getAnchorScope()); |
--- |
10829 |
getAnchorScope()); |
--- |
| 10830 |
getState() = NewS; |
0 |
10830 |
getState() = NewS; |
0 |
| 10831 |
} |
0 |
10831 |
} |
0 |
| 10832 |
|
--- |
10832 |
|
--- |
| 10833 |
/// See AbstractState::indicatePessimisticFixpoint(...). |
--- |
10833 |
/// See AbstractState::indicatePessimisticFixpoint(...). |
--- |
| 10834 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
10834 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
| 10835 |
getState() = StateType::getBestState(getState()); |
0 |
10835 |
getState() = StateType::getBestState(getState()); |
0 |
| 10836 |
getState().unionAssumed({{getAssociatedValue(), getCtxI()}, AA::AnyScope}); |
0 |
10836 |
getState().unionAssumed({{getAssociatedValue(), getCtxI()}, AA::AnyScope}); |
0 |
| 10837 |
AAPotentialValues::indicateOptimisticFixpoint(); |
0 |
10837 |
AAPotentialValues::indicateOptimisticFixpoint(); |
0 |
| 10838 |
return ChangeStatus::CHANGED; |
0 |
10838 |
return ChangeStatus::CHANGED; |
0 |
| 10839 |
} |
--- |
10839 |
} |
--- |
| 10840 |
|
--- |
10840 |
|
--- |
| 10841 |
/// See AbstractAttribute::updateImpl(...). |
--- |
10841 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 10842 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
10842 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 10843 |
return indicatePessimisticFixpoint(); |
0 |
10843 |
return indicatePessimisticFixpoint(); |
0 |
| 10844 |
} |
--- |
10844 |
} |
--- |
| 10845 |
|
--- |
10845 |
|
--- |
| 10846 |
/// See AbstractAttribute::manifest(...). |
--- |
10846 |
/// See AbstractAttribute::manifest(...). |
--- |
| 10847 |
ChangeStatus manifest(Attributor &A) override { |
0 |
10847 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 10848 |
SmallVector Values; |
0 |
10848 |
SmallVector Values; |
0 |
| 10849 |
for (AA::ValueScope S : {AA::Interprocedural, AA::Intraprocedural}) { |
0 |
10849 |
for (AA::ValueScope S : {AA::Interprocedural, AA::Intraprocedural}) { |
0 |
| 10850 |
Values.clear(); |
0 |
10850 |
Values.clear(); |
0 |
| 10851 |
if (!getAssumedSimplifiedValues(A, Values, S)) |
0 |
10851 |
if (!getAssumedSimplifiedValues(A, Values, S)) |
0 |
| 10852 |
continue; |
0 |
10852 |
continue; |
0 |
| 10853 |
Value &OldV = getAssociatedValue(); |
0 |
10853 |
Value &OldV = getAssociatedValue(); |
0 |
| 10854 |
if (isa(OldV)) |
0 |
10854 |
if (isa(OldV)) |
0 |
| 10855 |
continue; |
0 |
10855 |
continue; |
0 |
| 10856 |
Value *NewV = getSingleValue(A, *this, getIRPosition(), Values); |
0 |
10856 |
Value *NewV = getSingleValue(A, *this, getIRPosition(), Values); |
0 |
| 10857 |
if (!NewV || NewV == &OldV) |
0 |
10857 |
if (!NewV || NewV == &OldV) |
0 |
| 10858 |
continue; |
0 |
10858 |
continue; |
0 |
| 10859 |
if (getCtxI() && |
0 |
10859 |
if (getCtxI() && |
0 |
| 10860 |
!AA::isValidAtPosition({*NewV, *getCtxI()}, A.getInfoCache())) |
0 |
10860 |
!AA::isValidAtPosition({*NewV, *getCtxI()}, A.getInfoCache())) |
0 |
| 10861 |
continue; |
0 |
10861 |
continue; |
0 |
| 10862 |
if (A.changeAfterManifest(getIRPosition(), *NewV)) |
0 |
10862 |
if (A.changeAfterManifest(getIRPosition(), *NewV)) |
0 |
| 10863 |
return ChangeStatus::CHANGED; |
0 |
10863 |
return ChangeStatus::CHANGED; |
0 |
| 10864 |
} |
--- |
10864 |
} |
--- |
| 10865 |
return ChangeStatus::UNCHANGED; |
0 |
10865 |
return ChangeStatus::UNCHANGED; |
0 |
| 10866 |
} |
0 |
10866 |
} |
0 |
| 10867 |
|
--- |
10867 |
|
--- |
| 10868 |
bool getAssumedSimplifiedValues( |
0 |
10868 |
bool getAssumedSimplifiedValues( |
0 |
| 10869 |
Attributor &A, SmallVectorImpl &Values, |
--- |
10869 |
Attributor &A, SmallVectorImpl &Values, |
--- |
| 10870 |
AA::ValueScope S, bool RecurseForSelectAndPHI = false) const override { |
--- |
10870 |
AA::ValueScope S, bool RecurseForSelectAndPHI = false) const override { |
--- |
| 10871 |
if (!isValidState()) |
0 |
10871 |
if (!isValidState()) |
0 |
| 10872 |
return false; |
0 |
10872 |
return false; |
0 |
| 10873 |
bool UsedAssumedInformation = false; |
0 |
10873 |
bool UsedAssumedInformation = false; |
0 |
| 10874 |
for (const auto &It : getAssumedSet()) |
0 |
10874 |
for (const auto &It : getAssumedSet()) |
0 |
| 10875 |
if (It.second & S) { |
0 |
10875 |
if (It.second & S) { |
0 |
| 10876 |
if (RecurseForSelectAndPHI && (isa(It.first.getValue()) || |
0 |
10876 |
if (RecurseForSelectAndPHI && (isa(It.first.getValue()) || |
0 |
| 10877 |
isa(It.first.getValue()))) { |
0 |
10877 |
isa(It.first.getValue()))) { |
0 |
| 10878 |
if (A.getAssumedSimplifiedValues( |
0 |
10878 |
if (A.getAssumedSimplifiedValues( |
0 |
| 10879 |
IRPosition::inst(*cast(It.first.getValue())), |
0 |
10879 |
IRPosition::inst(*cast(It.first.getValue())), |
0 |
| 10880 |
this, Values, S, UsedAssumedInformation)) |
--- |
10880 |
this, Values, S, UsedAssumedInformation)) |
--- |
| 10881 |
continue; |
0 |
10881 |
continue; |
0 |
| 10882 |
} |
--- |
10882 |
} |
--- |
| 10883 |
Values.push_back(It.first); |
0 |
10883 |
Values.push_back(It.first); |
0 |
| 10884 |
} |
--- |
10884 |
} |
--- |
| 10885 |
assert(!undefIsContained() && "Undef should be an explicit value!"); |
0 |
10885 |
assert(!undefIsContained() && "Undef should be an explicit value!"); |
0 |
| 10886 |
return true; |
0 |
10886 |
return true; |
0 |
| 10887 |
} |
--- |
10887 |
} |
--- |
| 10888 |
}; |
--- |
10888 |
}; |
--- |
| 10889 |
|
--- |
10889 |
|
--- |
| 10890 |
struct AAPotentialValuesFloating : AAPotentialValuesImpl { |
--- |
10890 |
struct AAPotentialValuesFloating : AAPotentialValuesImpl { |
--- |
| 10891 |
AAPotentialValuesFloating(const IRPosition &IRP, Attributor &A) |
0 |
10891 |
AAPotentialValuesFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 10892 |
: AAPotentialValuesImpl(IRP, A) {} |
0 |
10892 |
: AAPotentialValuesImpl(IRP, A) {} |
0 |
| 10893 |
|
--- |
10893 |
|
--- |
| 10894 |
/// See AbstractAttribute::updateImpl(...). |
--- |
10894 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 10895 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
10895 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 10896 |
auto AssumedBefore = getAssumed(); |
0 |
10896 |
auto AssumedBefore = getAssumed(); |
0 |
| 10897 |
|
--- |
10897 |
|
--- |
| 10898 |
genericValueTraversal(A, &getAssociatedValue()); |
0 |
10898 |
genericValueTraversal(A, &getAssociatedValue()); |
0 |
| 10899 |
|
--- |
10899 |
|
--- |
| 10900 |
return (AssumedBefore == getAssumed()) ? ChangeStatus::UNCHANGED |
0 |
10900 |
return (AssumedBefore == getAssumed()) ? ChangeStatus::UNCHANGED |
0 |
| 10901 |
: ChangeStatus::CHANGED; |
0 |
10901 |
: ChangeStatus::CHANGED; |
0 |
| 10902 |
} |
0 |
10902 |
} |
0 |
| 10903 |
|
--- |
10903 |
|
--- |
| 10904 |
/// Helper struct to remember which AAIsDead instances we actually used. |
--- |
10904 |
/// Helper struct to remember which AAIsDead instances we actually used. |
--- |
| 10905 |
struct LivenessInfo { |
--- |
10905 |
struct LivenessInfo { |
--- |
| 10906 |
const AAIsDead *LivenessAA = nullptr; |
--- |
10906 |
const AAIsDead *LivenessAA = nullptr; |
--- |
| 10907 |
bool AnyDead = false; |
--- |
10907 |
bool AnyDead = false; |
--- |
| 10908 |
}; |
--- |
10908 |
}; |
--- |
| 10909 |
|
--- |
10909 |
|
--- |
| 10910 |
/// Check if \p Cmp is a comparison we can simplify. |
--- |
10910 |
/// Check if \p Cmp is a comparison we can simplify. |
--- |
| 10911 |
/// |
--- |
10911 |
/// |
--- |
| 10912 |
/// We handle multiple cases, one in which at least one operand is an |
--- |
10912 |
/// We handle multiple cases, one in which at least one operand is an |
--- |
| 10913 |
/// (assumed) nullptr. If so, try to simplify it using AANonNull on the other |
--- |
10913 |
/// (assumed) nullptr. If so, try to simplify it using AANonNull on the other |
--- |
| 10914 |
/// operand. Return true if successful, in that case Worklist will be updated. |
--- |
10914 |
/// operand. Return true if successful, in that case Worklist will be updated. |
--- |
| 10915 |
bool handleCmp(Attributor &A, Value &Cmp, Value *LHS, Value *RHS, |
0 |
10915 |
bool handleCmp(Attributor &A, Value &Cmp, Value *LHS, Value *RHS, |
0 |
| 10916 |
CmpInst::Predicate Pred, ItemInfo II, |
--- |
10916 |
CmpInst::Predicate Pred, ItemInfo II, |
--- |
| 10917 |
SmallVectorImpl &Worklist) { |
--- |
10917 |
SmallVectorImpl &Worklist) { |
--- |
| 10918 |
|
--- |
10918 |
|
--- |
| 10919 |
// Simplify the operands first. |
--- |
10919 |
// Simplify the operands first. |
--- |
| 10920 |
bool UsedAssumedInformation = false; |
0 |
10920 |
bool UsedAssumedInformation = false; |
0 |
| 10921 |
SmallVector LHSValues, RHSValues; |
0 |
10921 |
SmallVector LHSValues, RHSValues; |
0 |
| 10922 |
auto GetSimplifiedValues = [&](Value &V, |
0 |
10922 |
auto GetSimplifiedValues = [&](Value &V, |
0 |
| 10923 |
SmallVector &Values) { |
--- |
10923 |
SmallVector &Values) { |
--- |
| 10924 |
if (!A.getAssumedSimplifiedValues( |
0 |
10924 |
if (!A.getAssumedSimplifiedValues( |
0 |
| 10925 |
IRPosition::value(V, getCallBaseContext()), this, Values, |
0 |
10925 |
IRPosition::value(V, getCallBaseContext()), this, Values, |
0 |
| 10926 |
AA::Intraprocedural, UsedAssumedInformation)) { |
0 |
10926 |
AA::Intraprocedural, UsedAssumedInformation)) { |
0 |
| 10927 |
Values.clear(); |
0 |
10927 |
Values.clear(); |
0 |
| 10928 |
Values.push_back(AA::ValueAndContext{V, II.I.getCtxI()}); |
0 |
10928 |
Values.push_back(AA::ValueAndContext{V, II.I.getCtxI()}); |
0 |
| 10929 |
} |
--- |
10929 |
} |
--- |
| 10930 |
return Values.empty(); |
0 |
10930 |
return Values.empty(); |
0 |
| 10931 |
}; |
0 |
10931 |
}; |
0 |
| 10932 |
if (GetSimplifiedValues(*LHS, LHSValues)) |
0 |
10932 |
if (GetSimplifiedValues(*LHS, LHSValues)) |
0 |
| 10933 |
return true; |
0 |
10933 |
return true; |
0 |
| 10934 |
if (GetSimplifiedValues(*RHS, RHSValues)) |
0 |
10934 |
if (GetSimplifiedValues(*RHS, RHSValues)) |
0 |
| 10935 |
return true; |
0 |
10935 |
return true; |
0 |
| 10936 |
|
--- |
10936 |
|
--- |
| 10937 |
LLVMContext &Ctx = LHS->getContext(); |
0 |
10937 |
LLVMContext &Ctx = LHS->getContext(); |
0 |
| 10938 |
|
--- |
10938 |
|
--- |
| 10939 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
10939 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
| 10940 |
Instruction *CmpI = dyn_cast(&Cmp); |
0 |
10940 |
Instruction *CmpI = dyn_cast(&Cmp); |
0 |
| 10941 |
Function *F = CmpI ? CmpI->getFunction() : nullptr; |
0 |
10941 |
Function *F = CmpI ? CmpI->getFunction() : nullptr; |
0 |
| 10942 |
const auto *DT = |
--- |
10942 |
const auto *DT = |
--- |
| 10943 |
F ? InfoCache.getAnalysisResultForFunction(*F) |
0 |
10943 |
F ? InfoCache.getAnalysisResultForFunction(*F) |
0 |
| 10944 |
: nullptr; |
0 |
10944 |
: nullptr; |
0 |
| 10945 |
const auto *TLI = |
--- |
10945 |
const auto *TLI = |
--- |
| 10946 |
F ? A.getInfoCache().getTargetLibraryInfoForFunction(*F) : nullptr; |
0 |
10946 |
F ? A.getInfoCache().getTargetLibraryInfoForFunction(*F) : nullptr; |
0 |
| 10947 |
auto *AC = |
--- |
10947 |
auto *AC = |
--- |
| 10948 |
F ? InfoCache.getAnalysisResultForFunction(*F) |
0 |
10948 |
F ? InfoCache.getAnalysisResultForFunction(*F) |
0 |
| 10949 |
: nullptr; |
0 |
10949 |
: nullptr; |
0 |
| 10950 |
|
--- |
10950 |
|
--- |
| 10951 |
const DataLayout &DL = A.getDataLayout(); |
0 |
10951 |
const DataLayout &DL = A.getDataLayout(); |
0 |
| 10952 |
SimplifyQuery Q(DL, TLI, DT, AC, CmpI); |
0 |
10952 |
SimplifyQuery Q(DL, TLI, DT, AC, CmpI); |
0 |
| 10953 |
|
--- |
10953 |
|
--- |
| 10954 |
auto CheckPair = [&](Value &LHSV, Value &RHSV) { |
0 |
10954 |
auto CheckPair = [&](Value &LHSV, Value &RHSV) { |
0 |
| 10955 |
if (isa(LHSV) || isa(RHSV)) { |
0 |
10955 |
if (isa(LHSV) || isa(RHSV)) { |
0 |
| 10956 |
addValue(A, getState(), *UndefValue::get(Cmp.getType()), |
0 |
10956 |
addValue(A, getState(), *UndefValue::get(Cmp.getType()), |
0 |
| 10957 |
/* CtxI */ nullptr, II.S, getAnchorScope()); |
0 |
10957 |
/* CtxI */ nullptr, II.S, getAnchorScope()); |
0 |
| 10958 |
return true; |
0 |
10958 |
return true; |
0 |
| 10959 |
} |
--- |
10959 |
} |
--- |
| 10960 |
|
--- |
10960 |
|
--- |
| 10961 |
// Handle the trivial case first in which we don't even need to think |
--- |
10961 |
// Handle the trivial case first in which we don't even need to think |
--- |
| 10962 |
// about null or non-null. |
--- |
10962 |
// about null or non-null. |
--- |
| 10963 |
if (&LHSV == &RHSV && |
0 |
10963 |
if (&LHSV == &RHSV && |
0 |
| 10964 |
(CmpInst::isTrueWhenEqual(Pred) || CmpInst::isFalseWhenEqual(Pred))) { |
0 |
10964 |
(CmpInst::isTrueWhenEqual(Pred) || CmpInst::isFalseWhenEqual(Pred))) { |
0 |
| 10965 |
Constant *NewV = ConstantInt::get(Type::getInt1Ty(Ctx), |
0 |
10965 |
Constant *NewV = ConstantInt::get(Type::getInt1Ty(Ctx), |
0 |
| 10966 |
CmpInst::isTrueWhenEqual(Pred)); |
0 |
10966 |
CmpInst::isTrueWhenEqual(Pred)); |
0 |
| 10967 |
addValue(A, getState(), *NewV, /* CtxI */ nullptr, II.S, |
0 |
10967 |
addValue(A, getState(), *NewV, /* CtxI */ nullptr, II.S, |
0 |
| 10968 |
getAnchorScope()); |
--- |
10968 |
getAnchorScope()); |
--- |
| 10969 |
return true; |
0 |
10969 |
return true; |
0 |
| 10970 |
} |
--- |
10970 |
} |
--- |
| 10971 |
|
--- |
10971 |
|
--- |
| 10972 |
auto *TypedLHS = AA::getWithType(LHSV, *LHS->getType()); |
0 |
10972 |
auto *TypedLHS = AA::getWithType(LHSV, *LHS->getType()); |
0 |
| 10973 |
auto *TypedRHS = AA::getWithType(RHSV, *RHS->getType()); |
0 |
10973 |
auto *TypedRHS = AA::getWithType(RHSV, *RHS->getType()); |
0 |
| 10974 |
if (TypedLHS && TypedRHS) { |
0 |
10974 |
if (TypedLHS && TypedRHS) { |
0 |
| 10975 |
Value *NewV = simplifyCmpInst(Pred, TypedLHS, TypedRHS, Q); |
0 |
10975 |
Value *NewV = simplifyCmpInst(Pred, TypedLHS, TypedRHS, Q); |
0 |
| 10976 |
if (NewV && NewV != &Cmp) { |
0 |
10976 |
if (NewV && NewV != &Cmp) { |
0 |
| 10977 |
addValue(A, getState(), *NewV, /* CtxI */ nullptr, II.S, |
0 |
10977 |
addValue(A, getState(), *NewV, /* CtxI */ nullptr, II.S, |
0 |
| 10978 |
getAnchorScope()); |
--- |
10978 |
getAnchorScope()); |
--- |
| 10979 |
return true; |
0 |
10979 |
return true; |
0 |
| 10980 |
} |
--- |
10980 |
} |
--- |
| 10981 |
} |
--- |
10981 |
} |
--- |
| 10982 |
|
--- |
10982 |
|
--- |
| 10983 |
// From now on we only handle equalities (==, !=). |
--- |
10983 |
// From now on we only handle equalities (==, !=). |
--- |
| 10984 |
if (!CmpInst::isEquality(Pred)) |
0 |
10984 |
if (!CmpInst::isEquality(Pred)) |
0 |
| 10985 |
return false; |
0 |
10985 |
return false; |
0 |
| 10986 |
|
--- |
10986 |
|
--- |
| 10987 |
bool LHSIsNull = isa(LHSV); |
0 |
10987 |
bool LHSIsNull = isa(LHSV); |
0 |
| 10988 |
bool RHSIsNull = isa(RHSV); |
0 |
10988 |
bool RHSIsNull = isa(RHSV); |
0 |
| 10989 |
if (!LHSIsNull && !RHSIsNull) |
0 |
10989 |
if (!LHSIsNull && !RHSIsNull) |
0 |
| 10990 |
return false; |
0 |
10990 |
return false; |
0 |
| 10991 |
|
--- |
10991 |
|
--- |
| 10992 |
// Left is the nullptr ==/!= non-nullptr case. We'll use AANonNull on the |
--- |
10992 |
// Left is the nullptr ==/!= non-nullptr case. We'll use AANonNull on the |
--- |
| 10993 |
// non-nullptr operand and if we assume it's non-null we can conclude the |
--- |
10993 |
// non-nullptr operand and if we assume it's non-null we can conclude the |
--- |
| 10994 |
// result of the comparison. |
--- |
10994 |
// result of the comparison. |
--- |
| 10995 |
assert((LHSIsNull || RHSIsNull) && |
0 |
10995 |
assert((LHSIsNull || RHSIsNull) && |
0 |
| 10996 |
"Expected nullptr versus non-nullptr comparison at this point"); |
--- |
10996 |
"Expected nullptr versus non-nullptr comparison at this point"); |
--- |
| 10997 |
|
--- |
10997 |
|
--- |
| 10998 |
// The index is the operand that we assume is not null. |
--- |
10998 |
// The index is the operand that we assume is not null. |
--- |
| 10999 |
unsigned PtrIdx = LHSIsNull; |
0 |
10999 |
unsigned PtrIdx = LHSIsNull; |
0 |
| 11000 |
bool IsKnownNonNull; |
--- |
11000 |
bool IsKnownNonNull; |
--- |
| 11001 |
bool IsAssumedNonNull = AA::hasAssumedIRAttr( |
0 |
11001 |
bool IsAssumedNonNull = AA::hasAssumedIRAttr( |
0 |
| 11002 |
A, this, IRPosition::value(*(PtrIdx ? &RHSV : &LHSV)), |
0 |
11002 |
A, this, IRPosition::value(*(PtrIdx ? &RHSV : &LHSV)), |
0 |
| 11003 |
DepClassTy::REQUIRED, IsKnownNonNull); |
--- |
11003 |
DepClassTy::REQUIRED, IsKnownNonNull); |
--- |
| 11004 |
if (!IsAssumedNonNull) |
0 |
11004 |
if (!IsAssumedNonNull) |
0 |
| 11005 |
return false; |
0 |
11005 |
return false; |
0 |
| 11006 |
|
--- |
11006 |
|
--- |
| 11007 |
// The new value depends on the predicate, true for != and false for ==. |
--- |
11007 |
// The new value depends on the predicate, true for != and false for ==. |
--- |
| 11008 |
Constant *NewV = |
--- |
11008 |
Constant *NewV = |
--- |
| 11009 |
ConstantInt::get(Type::getInt1Ty(Ctx), Pred == CmpInst::ICMP_NE); |
0 |
11009 |
ConstantInt::get(Type::getInt1Ty(Ctx), Pred == CmpInst::ICMP_NE); |
0 |
| 11010 |
addValue(A, getState(), *NewV, /* CtxI */ nullptr, II.S, |
0 |
11010 |
addValue(A, getState(), *NewV, /* CtxI */ nullptr, II.S, |
0 |
| 11011 |
getAnchorScope()); |
--- |
11011 |
getAnchorScope()); |
--- |
| 11012 |
return true; |
0 |
11012 |
return true; |
0 |
| 11013 |
}; |
0 |
11013 |
}; |
0 |
| 11014 |
|
--- |
11014 |
|
--- |
| 11015 |
for (auto &LHSValue : LHSValues) |
0 |
11015 |
for (auto &LHSValue : LHSValues) |
0 |
| 11016 |
for (auto &RHSValue : RHSValues) |
0 |
11016 |
for (auto &RHSValue : RHSValues) |
0 |
| 11017 |
if (!CheckPair(*LHSValue.getValue(), *RHSValue.getValue())) |
0 |
11017 |
if (!CheckPair(*LHSValue.getValue(), *RHSValue.getValue())) |
0 |
| 11018 |
return false; |
0 |
11018 |
return false; |
0 |
| 11019 |
return true; |
0 |
11019 |
return true; |
0 |
| 11020 |
} |
0 |
11020 |
} |
0 |
| 11021 |
|
--- |
11021 |
|
--- |
| 11022 |
bool handleSelectInst(Attributor &A, SelectInst &SI, ItemInfo II, |
0 |
11022 |
bool handleSelectInst(Attributor &A, SelectInst &SI, ItemInfo II, |
0 |
| 11023 |
SmallVectorImpl &Worklist) { |
--- |
11023 |
SmallVectorImpl &Worklist) { |
--- |
| 11024 |
const Instruction *CtxI = II.I.getCtxI(); |
0 |
11024 |
const Instruction *CtxI = II.I.getCtxI(); |
0 |
| 11025 |
bool UsedAssumedInformation = false; |
0 |
11025 |
bool UsedAssumedInformation = false; |
0 |
| 11026 |
|
--- |
11026 |
|
--- |
| 11027 |
std::optional C = |
--- |
11027 |
std::optional C = |
--- |
| 11028 |
A.getAssumedConstant(*SI.getCondition(), *this, UsedAssumedInformation); |
0 |
11028 |
A.getAssumedConstant(*SI.getCondition(), *this, UsedAssumedInformation); |
0 |
| 11029 |
bool NoValueYet = !C.has_value(); |
0 |
11029 |
bool NoValueYet = !C.has_value(); |
0 |
| 11030 |
if (NoValueYet || isa_and_nonnull(*C)) |
0 |
11030 |
if (NoValueYet || isa_and_nonnull(*C)) |
0 |
| 11031 |
return true; |
0 |
11031 |
return true; |
0 |
| 11032 |
if (auto *CI = dyn_cast_or_null(*C)) { |
0 |
11032 |
if (auto *CI = dyn_cast_or_null(*C)) { |
0 |
| 11033 |
if (CI->isZero()) |
0 |
11033 |
if (CI->isZero()) |
0 |
| 11034 |
Worklist.push_back({{*SI.getFalseValue(), CtxI}, II.S}); |
0 |
11034 |
Worklist.push_back({{*SI.getFalseValue(), CtxI}, II.S}); |
0 |
| 11035 |
else |
--- |
11035 |
else |
--- |
| 11036 |
Worklist.push_back({{*SI.getTrueValue(), CtxI}, II.S}); |
0 |
11036 |
Worklist.push_back({{*SI.getTrueValue(), CtxI}, II.S}); |
0 |
| 11037 |
} else if (&SI == &getAssociatedValue()) { |
0 |
11037 |
} else if (&SI == &getAssociatedValue()) { |
0 |
| 11038 |
// We could not simplify the condition, assume both values. |
--- |
11038 |
// We could not simplify the condition, assume both values. |
--- |
| 11039 |
Worklist.push_back({{*SI.getTrueValue(), CtxI}, II.S}); |
0 |
11039 |
Worklist.push_back({{*SI.getTrueValue(), CtxI}, II.S}); |
0 |
| 11040 |
Worklist.push_back({{*SI.getFalseValue(), CtxI}, II.S}); |
0 |
11040 |
Worklist.push_back({{*SI.getFalseValue(), CtxI}, II.S}); |
0 |
| 11041 |
} else { |
--- |
11041 |
} else { |
--- |
| 11042 |
std::optional SimpleV = A.getAssumedSimplified( |
0 |
11042 |
std::optional SimpleV = A.getAssumedSimplified( |
0 |
| 11043 |
IRPosition::inst(SI), *this, UsedAssumedInformation, II.S); |
0 |
11043 |
IRPosition::inst(SI), *this, UsedAssumedInformation, II.S); |
0 |
| 11044 |
if (!SimpleV.has_value()) |
0 |
11044 |
if (!SimpleV.has_value()) |
0 |
| 11045 |
return true; |
0 |
11045 |
return true; |
0 |
| 11046 |
if (*SimpleV) { |
0 |
11046 |
if (*SimpleV) { |
0 |
| 11047 |
addValue(A, getState(), **SimpleV, CtxI, II.S, getAnchorScope()); |
0 |
11047 |
addValue(A, getState(), **SimpleV, CtxI, II.S, getAnchorScope()); |
0 |
| 11048 |
return true; |
0 |
11048 |
return true; |
0 |
| 11049 |
} |
--- |
11049 |
} |
--- |
| 11050 |
return false; |
0 |
11050 |
return false; |
0 |
| 11051 |
} |
--- |
11051 |
} |
--- |
| 11052 |
return true; |
0 |
11052 |
return true; |
0 |
| 11053 |
} |
--- |
11053 |
} |
--- |
| 11054 |
|
--- |
11054 |
|
--- |
| 11055 |
bool handleLoadInst(Attributor &A, LoadInst &LI, ItemInfo II, |
0 |
11055 |
bool handleLoadInst(Attributor &A, LoadInst &LI, ItemInfo II, |
0 |
| 11056 |
SmallVectorImpl &Worklist) { |
--- |
11056 |
SmallVectorImpl &Worklist) { |
--- |
| 11057 |
SmallSetVector PotentialCopies; |
0 |
11057 |
SmallSetVector PotentialCopies; |
0 |
| 11058 |
SmallSetVector PotentialValueOrigins; |
0 |
11058 |
SmallSetVector PotentialValueOrigins; |
0 |
| 11059 |
bool UsedAssumedInformation = false; |
0 |
11059 |
bool UsedAssumedInformation = false; |
0 |
| 11060 |
if (!AA::getPotentiallyLoadedValues(A, LI, PotentialCopies, |
0 |
11060 |
if (!AA::getPotentiallyLoadedValues(A, LI, PotentialCopies, |
0 |
| 11061 |
PotentialValueOrigins, *this, |
--- |
11061 |
PotentialValueOrigins, *this, |
--- |
| 11062 |
UsedAssumedInformation, |
--- |
11062 |
UsedAssumedInformation, |
--- |
| 11063 |
/* OnlyExact */ true)) { |
--- |
11063 |
/* OnlyExact */ true)) { |
--- |
| 11064 |
LLVM_DEBUG(dbgs() << "[AAPotentialValues] Failed to get potentially " |
0 |
11064 |
LLVM_DEBUG(dbgs() << "[AAPotentialValues] Failed to get potentially " |
0 |
| 11065 |
"loaded values for load instruction " |
--- |
11065 |
"loaded values for load instruction " |
--- |
| 11066 |
<< LI << "\n"); |
--- |
11066 |
<< LI << "\n"); |
--- |
| 11067 |
return false; |
0 |
11067 |
return false; |
0 |
| 11068 |
} |
--- |
11068 |
} |
--- |
| 11069 |
|
--- |
11069 |
|
--- |
| 11070 |
// Do not simplify loads that are only used in llvm.assume if we cannot also |
--- |
11070 |
// Do not simplify loads that are only used in llvm.assume if we cannot also |
--- |
| 11071 |
// remove all stores that may feed into the load. The reason is that the |
--- |
11071 |
// remove all stores that may feed into the load. The reason is that the |
--- |
| 11072 |
// assume is probably worth something as long as the stores are around. |
--- |
11072 |
// assume is probably worth something as long as the stores are around. |
--- |
| 11073 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
11073 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
| 11074 |
if (InfoCache.isOnlyUsedByAssume(LI)) { |
0 |
11074 |
if (InfoCache.isOnlyUsedByAssume(LI)) { |
0 |
| 11075 |
if (!llvm::all_of(PotentialValueOrigins, [&](Instruction *I) { |
0 |
11075 |
if (!llvm::all_of(PotentialValueOrigins, [&](Instruction *I) { |
0 |
| 11076 |
if (!I || isa(I)) |
0 |
11076 |
if (!I || isa(I)) |
0 |
| 11077 |
return true; |
0 |
11077 |
return true; |
0 |
| 11078 |
if (auto *SI = dyn_cast(I)) |
0 |
11078 |
if (auto *SI = dyn_cast(I)) |
0 |
| 11079 |
return A.isAssumedDead(SI->getOperandUse(0), this, |
0 |
11079 |
return A.isAssumedDead(SI->getOperandUse(0), this, |
0 |
| 11080 |
/* LivenessAA */ nullptr, |
--- |
11080 |
/* LivenessAA */ nullptr, |
--- |
| 11081 |
UsedAssumedInformation, |
0 |
11081 |
UsedAssumedInformation, |
0 |
| 11082 |
/* CheckBBLivenessOnly */ false); |
0 |
11082 |
/* CheckBBLivenessOnly */ false); |
0 |
| 11083 |
return A.isAssumedDead(*I, this, /* LivenessAA */ nullptr, |
0 |
11083 |
return A.isAssumedDead(*I, this, /* LivenessAA */ nullptr, |
0 |
| 11084 |
UsedAssumedInformation, |
--- |
11084 |
UsedAssumedInformation, |
--- |
| 11085 |
/* CheckBBLivenessOnly */ false); |
0 |
11085 |
/* CheckBBLivenessOnly */ false); |
0 |
| 11086 |
})) { |
--- |
11086 |
})) { |
--- |
| 11087 |
LLVM_DEBUG(dbgs() << "[AAPotentialValues] Load is onl used by assumes " |
0 |
11087 |
LLVM_DEBUG(dbgs() << "[AAPotentialValues] Load is onl used by assumes " |
0 |
| 11088 |
"and we cannot delete all the stores: " |
--- |
11088 |
"and we cannot delete all the stores: " |
--- |
| 11089 |
<< LI << "\n"); |
--- |
11089 |
<< LI << "\n"); |
--- |
| 11090 |
return false; |
0 |
11090 |
return false; |
0 |
| 11091 |
} |
--- |
11091 |
} |
--- |
| 11092 |
} |
--- |
11092 |
} |
--- |
| 11093 |
|
--- |
11093 |
|
--- |
| 11094 |
// Values have to be dynamically unique or we loose the fact that a |
--- |
11094 |
// Values have to be dynamically unique or we loose the fact that a |
--- |
| 11095 |
// single llvm::Value might represent two runtime values (e.g., |
--- |
11095 |
// single llvm::Value might represent two runtime values (e.g., |
--- |
| 11096 |
// stack locations in different recursive calls). |
--- |
11096 |
// stack locations in different recursive calls). |
--- |
| 11097 |
const Instruction *CtxI = II.I.getCtxI(); |
0 |
11097 |
const Instruction *CtxI = II.I.getCtxI(); |
0 |
| 11098 |
bool ScopeIsLocal = (II.S & AA::Intraprocedural); |
0 |
11098 |
bool ScopeIsLocal = (II.S & AA::Intraprocedural); |
0 |
| 11099 |
bool AllLocal = ScopeIsLocal; |
0 |
11099 |
bool AllLocal = ScopeIsLocal; |
0 |
| 11100 |
bool DynamicallyUnique = llvm::all_of(PotentialCopies, [&](Value *PC) { |
0 |
11100 |
bool DynamicallyUnique = llvm::all_of(PotentialCopies, [&](Value *PC) { |
0 |
| 11101 |
AllLocal &= AA::isValidInScope(*PC, getAnchorScope()); |
0 |
11101 |
AllLocal &= AA::isValidInScope(*PC, getAnchorScope()); |
0 |
| 11102 |
return AA::isDynamicallyUnique(A, *this, *PC); |
0 |
11102 |
return AA::isDynamicallyUnique(A, *this, *PC); |
0 |
| 11103 |
}); |
--- |
11103 |
}); |
--- |
| 11104 |
if (!DynamicallyUnique) { |
0 |
11104 |
if (!DynamicallyUnique) { |
0 |
| 11105 |
LLVM_DEBUG(dbgs() << "[AAPotentialValues] Not all potentially loaded " |
0 |
11105 |
LLVM_DEBUG(dbgs() << "[AAPotentialValues] Not all potentially loaded " |
0 |
| 11106 |
"values are dynamically unique: " |
--- |
11106 |
"values are dynamically unique: " |
--- |
| 11107 |
<< LI << "\n"); |
--- |
11107 |
<< LI << "\n"); |
--- |
| 11108 |
return false; |
0 |
11108 |
return false; |
0 |
| 11109 |
} |
--- |
11109 |
} |
--- |
| 11110 |
|
--- |
11110 |
|
--- |
| 11111 |
for (auto *PotentialCopy : PotentialCopies) { |
0 |
11111 |
for (auto *PotentialCopy : PotentialCopies) { |
0 |
| 11112 |
if (AllLocal) { |
0 |
11112 |
if (AllLocal) { |
0 |
| 11113 |
Worklist.push_back({{*PotentialCopy, CtxI}, II.S}); |
0 |
11113 |
Worklist.push_back({{*PotentialCopy, CtxI}, II.S}); |
0 |
| 11114 |
} else { |
--- |
11114 |
} else { |
--- |
| 11115 |
Worklist.push_back({{*PotentialCopy, CtxI}, AA::Interprocedural}); |
0 |
11115 |
Worklist.push_back({{*PotentialCopy, CtxI}, AA::Interprocedural}); |
0 |
| 11116 |
} |
--- |
11116 |
} |
--- |
| 11117 |
} |
--- |
11117 |
} |
--- |
| 11118 |
if (!AllLocal && ScopeIsLocal) |
0 |
11118 |
if (!AllLocal && ScopeIsLocal) |
0 |
| 11119 |
addValue(A, getState(), LI, CtxI, AA::Intraprocedural, getAnchorScope()); |
0 |
11119 |
addValue(A, getState(), LI, CtxI, AA::Intraprocedural, getAnchorScope()); |
0 |
| 11120 |
return true; |
0 |
11120 |
return true; |
0 |
| 11121 |
} |
0 |
11121 |
} |
0 |
| 11122 |
|
--- |
11122 |
|
--- |
| 11123 |
bool handlePHINode( |
0 |
11123 |
bool handlePHINode( |
0 |
| 11124 |
Attributor &A, PHINode &PHI, ItemInfo II, |
--- |
11124 |
Attributor &A, PHINode &PHI, ItemInfo II, |
--- |
| 11125 |
SmallVectorImpl &Worklist, |
--- |
11125 |
SmallVectorImpl &Worklist, |
--- |
| 11126 |
SmallMapVector &LivenessAAs) { |
--- |
11126 |
SmallMapVector &LivenessAAs) { |
--- |
| 11127 |
auto GetLivenessInfo = [&](const Function &F) -> LivenessInfo & { |
0 |
11127 |
auto GetLivenessInfo = [&](const Function &F) -> LivenessInfo & { |
0 |
| 11128 |
LivenessInfo &LI = LivenessAAs[&F]; |
0 |
11128 |
LivenessInfo &LI = LivenessAAs[&F]; |
0 |
| 11129 |
if (!LI.LivenessAA) |
0 |
11129 |
if (!LI.LivenessAA) |
0 |
| 11130 |
LI.LivenessAA = A.getAAFor(*this, IRPosition::function(F), |
0 |
11130 |
LI.LivenessAA = A.getAAFor(*this, IRPosition::function(F), |
0 |
| 11131 |
DepClassTy::NONE); |
--- |
11131 |
DepClassTy::NONE); |
--- |
| 11132 |
return LI; |
0 |
11132 |
return LI; |
0 |
| 11133 |
}; |
0 |
11133 |
}; |
0 |
| 11134 |
|
--- |
11134 |
|
--- |
| 11135 |
if (&PHI == &getAssociatedValue()) { |
0 |
11135 |
if (&PHI == &getAssociatedValue()) { |
0 |
| 11136 |
LivenessInfo &LI = GetLivenessInfo(*PHI.getFunction()); |
0 |
11136 |
LivenessInfo &LI = GetLivenessInfo(*PHI.getFunction()); |
0 |
| 11137 |
const auto *CI = |
--- |
11137 |
const auto *CI = |
--- |
| 11138 |
A.getInfoCache().getAnalysisResultForFunction( |
0 |
11138 |
A.getInfoCache().getAnalysisResultForFunction( |
0 |
| 11139 |
*PHI.getFunction()); |
0 |
11139 |
*PHI.getFunction()); |
0 |
| 11140 |
|
--- |
11140 |
|
--- |
| 11141 |
Cycle *C = nullptr; |
0 |
11141 |
Cycle *C = nullptr; |
0 |
| 11142 |
bool CyclePHI = mayBeInCycle(CI, &PHI, /* HeaderOnly */ true, &C); |
0 |
11142 |
bool CyclePHI = mayBeInCycle(CI, &PHI, /* HeaderOnly */ true, &C); |
0 |
| 11143 |
for (unsigned u = 0, e = PHI.getNumIncomingValues(); u < e; u++) { |
0 |
11143 |
for (unsigned u = 0, e = PHI.getNumIncomingValues(); u < e; u++) { |
0 |
| 11144 |
BasicBlock *IncomingBB = PHI.getIncomingBlock(u); |
0 |
11144 |
BasicBlock *IncomingBB = PHI.getIncomingBlock(u); |
0 |
| 11145 |
if (LI.LivenessAA && |
0 |
11145 |
if (LI.LivenessAA && |
0 |
| 11146 |
LI.LivenessAA->isEdgeDead(IncomingBB, PHI.getParent())) { |
0 |
11146 |
LI.LivenessAA->isEdgeDead(IncomingBB, PHI.getParent())) { |
0 |
| 11147 |
LI.AnyDead = true; |
0 |
11147 |
LI.AnyDead = true; |
0 |
| 11148 |
continue; |
0 |
11148 |
continue; |
0 |
| 11149 |
} |
--- |
11149 |
} |
--- |
| 11150 |
Value *V = PHI.getIncomingValue(u); |
0 |
11150 |
Value *V = PHI.getIncomingValue(u); |
0 |
| 11151 |
if (V == &PHI) |
0 |
11151 |
if (V == &PHI) |
0 |
| 11152 |
continue; |
0 |
11152 |
continue; |
0 |
| 11153 |
|
--- |
11153 |
|
--- |
| 11154 |
// If the incoming value is not the PHI but an instruction in the same |
--- |
11154 |
// If the incoming value is not the PHI but an instruction in the same |
--- |
| 11155 |
// cycle we might have multiple versions of it flying around. |
--- |
11155 |
// cycle we might have multiple versions of it flying around. |
--- |
| 11156 |
if (CyclePHI && isa(V) && |
0 |
11156 |
if (CyclePHI && isa(V) && |
0 |
| 11157 |
(!C || C->contains(cast(V)->getParent()))) |
0 |
11157 |
(!C || C->contains(cast(V)->getParent()))) |
0 |
| 11158 |
return false; |
0 |
11158 |
return false; |
0 |
| 11159 |
|
--- |
11159 |
|
--- |
| 11160 |
Worklist.push_back({{*V, IncomingBB->getTerminator()}, II.S}); |
0 |
11160 |
Worklist.push_back({{*V, IncomingBB->getTerminator()}, II.S}); |
0 |
| 11161 |
} |
--- |
11161 |
} |
--- |
| 11162 |
return true; |
0 |
11162 |
return true; |
0 |
| 11163 |
} |
--- |
11163 |
} |
--- |
| 11164 |
|
--- |
11164 |
|
--- |
| 11165 |
bool UsedAssumedInformation = false; |
0 |
11165 |
bool UsedAssumedInformation = false; |
0 |
| 11166 |
std::optional SimpleV = A.getAssumedSimplified( |
0 |
11166 |
std::optional SimpleV = A.getAssumedSimplified( |
0 |
| 11167 |
IRPosition::inst(PHI), *this, UsedAssumedInformation, II.S); |
0 |
11167 |
IRPosition::inst(PHI), *this, UsedAssumedInformation, II.S); |
0 |
| 11168 |
if (!SimpleV.has_value()) |
0 |
11168 |
if (!SimpleV.has_value()) |
0 |
| 11169 |
return true; |
0 |
11169 |
return true; |
0 |
| 11170 |
if (!(*SimpleV)) |
0 |
11170 |
if (!(*SimpleV)) |
0 |
| 11171 |
return false; |
0 |
11171 |
return false; |
0 |
| 11172 |
addValue(A, getState(), **SimpleV, &PHI, II.S, getAnchorScope()); |
0 |
11172 |
addValue(A, getState(), **SimpleV, &PHI, II.S, getAnchorScope()); |
0 |
| 11173 |
return true; |
0 |
11173 |
return true; |
0 |
| 11174 |
} |
--- |
11174 |
} |
--- |
| 11175 |
|
--- |
11175 |
|
--- |
| 11176 |
/// Use the generic, non-optimistic InstSimplfy functionality if we managed to |
--- |
11176 |
/// Use the generic, non-optimistic InstSimplfy functionality if we managed to |
--- |
| 11177 |
/// simplify any operand of the instruction \p I. Return true if successful, |
--- |
11177 |
/// simplify any operand of the instruction \p I. Return true if successful, |
--- |
| 11178 |
/// in that case Worklist will be updated. |
--- |
11178 |
/// in that case Worklist will be updated. |
--- |
| 11179 |
bool handleGenericInst(Attributor &A, Instruction &I, ItemInfo II, |
0 |
11179 |
bool handleGenericInst(Attributor &A, Instruction &I, ItemInfo II, |
0 |
| 11180 |
SmallVectorImpl &Worklist) { |
--- |
11180 |
SmallVectorImpl &Worklist) { |
--- |
| 11181 |
bool SomeSimplified = false; |
0 |
11181 |
bool SomeSimplified = false; |
0 |
| 11182 |
bool UsedAssumedInformation = false; |
0 |
11182 |
bool UsedAssumedInformation = false; |
0 |
| 11183 |
|
--- |
11183 |
|
--- |
| 11184 |
SmallVector NewOps(I.getNumOperands()); |
0 |
11184 |
SmallVector NewOps(I.getNumOperands()); |
0 |
| 11185 |
int Idx = 0; |
0 |
11185 |
int Idx = 0; |
0 |
| 11186 |
for (Value *Op : I.operands()) { |
0 |
11186 |
for (Value *Op : I.operands()) { |
0 |
| 11187 |
const auto &SimplifiedOp = A.getAssumedSimplified( |
0 |
11187 |
const auto &SimplifiedOp = A.getAssumedSimplified( |
0 |
| 11188 |
IRPosition::value(*Op, getCallBaseContext()), *this, |
0 |
11188 |
IRPosition::value(*Op, getCallBaseContext()), *this, |
0 |
| 11189 |
UsedAssumedInformation, AA::Intraprocedural); |
0 |
11189 |
UsedAssumedInformation, AA::Intraprocedural); |
0 |
| 11190 |
// If we are not sure about any operand we are not sure about the entire |
--- |
11190 |
// If we are not sure about any operand we are not sure about the entire |
--- |
| 11191 |
// instruction, we'll wait. |
--- |
11191 |
// instruction, we'll wait. |
--- |
| 11192 |
if (!SimplifiedOp.has_value()) |
0 |
11192 |
if (!SimplifiedOp.has_value()) |
0 |
| 11193 |
return true; |
0 |
11193 |
return true; |
0 |
| 11194 |
|
--- |
11194 |
|
--- |
| 11195 |
if (*SimplifiedOp) |
0 |
11195 |
if (*SimplifiedOp) |
0 |
| 11196 |
NewOps[Idx] = *SimplifiedOp; |
0 |
11196 |
NewOps[Idx] = *SimplifiedOp; |
0 |
| 11197 |
else |
--- |
11197 |
else |
--- |
| 11198 |
NewOps[Idx] = Op; |
0 |
11198 |
NewOps[Idx] = Op; |
0 |
| 11199 |
|
--- |
11199 |
|
--- |
| 11200 |
SomeSimplified |= (NewOps[Idx] != Op); |
0 |
11200 |
SomeSimplified |= (NewOps[Idx] != Op); |
0 |
| 11201 |
++Idx; |
0 |
11201 |
++Idx; |
0 |
| 11202 |
} |
--- |
11202 |
} |
--- |
| 11203 |
|
--- |
11203 |
|
--- |
| 11204 |
// We won't bother with the InstSimplify interface if we didn't simplify any |
--- |
11204 |
// We won't bother with the InstSimplify interface if we didn't simplify any |
--- |
| 11205 |
// operand ourselves. |
--- |
11205 |
// operand ourselves. |
--- |
| 11206 |
if (!SomeSimplified) |
0 |
11206 |
if (!SomeSimplified) |
0 |
| 11207 |
return false; |
0 |
11207 |
return false; |
0 |
| 11208 |
|
--- |
11208 |
|
--- |
| 11209 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
11209 |
InformationCache &InfoCache = A.getInfoCache(); |
0 |
| 11210 |
Function *F = I.getFunction(); |
0 |
11210 |
Function *F = I.getFunction(); |
0 |
| 11211 |
const auto *DT = |
--- |
11211 |
const auto *DT = |
--- |
| 11212 |
InfoCache.getAnalysisResultForFunction(*F); |
0 |
11212 |
InfoCache.getAnalysisResultForFunction(*F); |
0 |
| 11213 |
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F); |
0 |
11213 |
const auto *TLI = A.getInfoCache().getTargetLibraryInfoForFunction(*F); |
0 |
| 11214 |
auto *AC = InfoCache.getAnalysisResultForFunction(*F); |
0 |
11214 |
auto *AC = InfoCache.getAnalysisResultForFunction(*F); |
0 |
| 11215 |
|
--- |
11215 |
|
--- |
| 11216 |
const DataLayout &DL = I.getModule()->getDataLayout(); |
0 |
11216 |
const DataLayout &DL = I.getModule()->getDataLayout(); |
0 |
| 11217 |
SimplifyQuery Q(DL, TLI, DT, AC, &I); |
0 |
11217 |
SimplifyQuery Q(DL, TLI, DT, AC, &I); |
0 |
| 11218 |
Value *NewV = simplifyInstructionWithOperands(&I, NewOps, Q); |
0 |
11218 |
Value *NewV = simplifyInstructionWithOperands(&I, NewOps, Q); |
0 |
| 11219 |
if (!NewV || NewV == &I) |
0 |
11219 |
if (!NewV || NewV == &I) |
0 |
| 11220 |
return false; |
0 |
11220 |
return false; |
0 |
| 11221 |
|
--- |
11221 |
|
--- |
| 11222 |
LLVM_DEBUG(dbgs() << "Generic inst " << I << " assumed simplified to " |
0 |
11222 |
LLVM_DEBUG(dbgs() << "Generic inst " << I << " assumed simplified to " |
0 |
| 11223 |
<< *NewV << "\n"); |
--- |
11223 |
<< *NewV << "\n"); |
--- |
| 11224 |
Worklist.push_back({{*NewV, II.I.getCtxI()}, II.S}); |
0 |
11224 |
Worklist.push_back({{*NewV, II.I.getCtxI()}, II.S}); |
0 |
| 11225 |
return true; |
0 |
11225 |
return true; |
0 |
| 11226 |
} |
0 |
11226 |
} |
0 |
| 11227 |
|
--- |
11227 |
|
--- |
| 11228 |
bool simplifyInstruction( |
0 |
11228 |
bool simplifyInstruction( |
0 |
| 11229 |
Attributor &A, Instruction &I, ItemInfo II, |
--- |
11229 |
Attributor &A, Instruction &I, ItemInfo II, |
--- |
| 11230 |
SmallVectorImpl &Worklist, |
--- |
11230 |
SmallVectorImpl &Worklist, |
--- |
| 11231 |
SmallMapVector &LivenessAAs) { |
--- |
11231 |
SmallMapVector &LivenessAAs) { |
--- |
| 11232 |
if (auto *CI = dyn_cast(&I)) |
0 |
11232 |
if (auto *CI = dyn_cast(&I)) |
0 |
| 11233 |
return handleCmp(A, *CI, CI->getOperand(0), CI->getOperand(1), |
0 |
11233 |
return handleCmp(A, *CI, CI->getOperand(0), CI->getOperand(1), |
0 |
| 11234 |
CI->getPredicate(), II, Worklist); |
0 |
11234 |
CI->getPredicate(), II, Worklist); |
0 |
| 11235 |
|
--- |
11235 |
|
--- |
| 11236 |
switch (I.getOpcode()) { |
0 |
11236 |
switch (I.getOpcode()) { |
0 |
| 11237 |
case Instruction::Select: |
0 |
11237 |
case Instruction::Select: |
0 |
| 11238 |
return handleSelectInst(A, cast(I), II, Worklist); |
0 |
11238 |
return handleSelectInst(A, cast(I), II, Worklist); |
0 |
| 11239 |
case Instruction::PHI: |
0 |
11239 |
case Instruction::PHI: |
0 |
| 11240 |
return handlePHINode(A, cast(I), II, Worklist, LivenessAAs); |
0 |
11240 |
return handlePHINode(A, cast(I), II, Worklist, LivenessAAs); |
0 |
| 11241 |
case Instruction::Load: |
0 |
11241 |
case Instruction::Load: |
0 |
| 11242 |
return handleLoadInst(A, cast(I), II, Worklist); |
0 |
11242 |
return handleLoadInst(A, cast(I), II, Worklist); |
0 |
| 11243 |
default: |
0 |
11243 |
default: |
0 |
| 11244 |
return handleGenericInst(A, I, II, Worklist); |
0 |
11244 |
return handleGenericInst(A, I, II, Worklist); |
0 |
| 11245 |
}; |
--- |
11245 |
}; |
--- |
| 11246 |
return false; |
--- |
11246 |
return false; |
--- |
| 11247 |
} |
--- |
11247 |
} |
--- |
| 11248 |
|
--- |
11248 |
|
--- |
| 11249 |
void genericValueTraversal(Attributor &A, Value *InitialV) { |
0 |
11249 |
void genericValueTraversal(Attributor &A, Value *InitialV) { |
0 |
| 11250 |
SmallMapVector LivenessAAs; |
0 |
11250 |
SmallMapVector LivenessAAs; |
0 |
| 11251 |
|
--- |
11251 |
|
--- |
| 11252 |
SmallSet Visited; |
0 |
11252 |
SmallSet Visited; |
0 |
| 11253 |
SmallVector Worklist; |
0 |
11253 |
SmallVector Worklist; |
0 |
| 11254 |
Worklist.push_back({{*InitialV, getCtxI()}, AA::AnyScope}); |
0 |
11254 |
Worklist.push_back({{*InitialV, getCtxI()}, AA::AnyScope}); |
0 |
| 11255 |
|
--- |
11255 |
|
--- |
| 11256 |
int Iteration = 0; |
0 |
11256 |
int Iteration = 0; |
0 |
| 11257 |
do { |
--- |
11257 |
do { |
--- |
| 11258 |
ItemInfo II = Worklist.pop_back_val(); |
0 |
11258 |
ItemInfo II = Worklist.pop_back_val(); |
0 |
| 11259 |
Value *V = II.I.getValue(); |
0 |
11259 |
Value *V = II.I.getValue(); |
0 |
| 11260 |
assert(V); |
0 |
11260 |
assert(V); |
0 |
| 11261 |
const Instruction *CtxI = II.I.getCtxI(); |
0 |
11261 |
const Instruction *CtxI = II.I.getCtxI(); |
0 |
| 11262 |
AA::ValueScope S = II.S; |
0 |
11262 |
AA::ValueScope S = II.S; |
0 |
| 11263 |
|
--- |
11263 |
|
--- |
| 11264 |
// Check if we should process the current value. To prevent endless |
--- |
11264 |
// Check if we should process the current value. To prevent endless |
--- |
| 11265 |
// recursion keep a record of the values we followed! |
--- |
11265 |
// recursion keep a record of the values we followed! |
--- |
| 11266 |
if (!Visited.insert(II).second) |
0 |
11266 |
if (!Visited.insert(II).second) |
0 |
| 11267 |
continue; |
0 |
11267 |
continue; |
0 |
| 11268 |
|
--- |
11268 |
|
--- |
| 11269 |
// Make sure we limit the compile time for complex expressions. |
--- |
11269 |
// Make sure we limit the compile time for complex expressions. |
--- |
| 11270 |
if (Iteration++ >= MaxPotentialValuesIterations) { |
0 |
11270 |
if (Iteration++ >= MaxPotentialValuesIterations) { |
0 |
| 11271 |
LLVM_DEBUG(dbgs() << "Generic value traversal reached iteration limit: " |
0 |
11271 |
LLVM_DEBUG(dbgs() << "Generic value traversal reached iteration limit: " |
0 |
| 11272 |
<< Iteration << "!\n"); |
--- |
11272 |
<< Iteration << "!\n"); |
--- |
| 11273 |
addValue(A, getState(), *V, CtxI, S, getAnchorScope()); |
0 |
11273 |
addValue(A, getState(), *V, CtxI, S, getAnchorScope()); |
0 |
| 11274 |
continue; |
0 |
11274 |
continue; |
0 |
| 11275 |
} |
--- |
11275 |
} |
--- |
| 11276 |
|
--- |
11276 |
|
--- |
| 11277 |
// Explicitly look through calls with a "returned" attribute if we do |
--- |
11277 |
// Explicitly look through calls with a "returned" attribute if we do |
--- |
| 11278 |
// not have a pointer as stripPointerCasts only works on them. |
--- |
11278 |
// not have a pointer as stripPointerCasts only works on them. |
--- |
| 11279 |
Value *NewV = nullptr; |
0 |
11279 |
Value *NewV = nullptr; |
0 |
| 11280 |
if (V->getType()->isPointerTy()) { |
0 |
11280 |
if (V->getType()->isPointerTy()) { |
0 |
| 11281 |
NewV = AA::getWithType(*V->stripPointerCasts(), *V->getType()); |
0 |
11281 |
NewV = AA::getWithType(*V->stripPointerCasts(), *V->getType()); |
0 |
| 11282 |
} else { |
--- |
11282 |
} else { |
--- |
| 11283 |
if (auto *CB = dyn_cast(V)) |
0 |
11283 |
if (auto *CB = dyn_cast(V)) |
0 |
| 11284 |
if (auto *Callee = |
0 |
11284 |
if (auto *Callee = |
0 |
| 11285 |
dyn_cast_if_present(CB->getCalledOperand())) { |
0 |
11285 |
dyn_cast_if_present(CB->getCalledOperand())) { |
0 |
| 11286 |
for (Argument &Arg : Callee->args()) |
0 |
11286 |
for (Argument &Arg : Callee->args()) |
0 |
| 11287 |
if (Arg.hasReturnedAttr()) { |
0 |
11287 |
if (Arg.hasReturnedAttr()) { |
0 |
| 11288 |
NewV = CB->getArgOperand(Arg.getArgNo()); |
0 |
11288 |
NewV = CB->getArgOperand(Arg.getArgNo()); |
0 |
| 11289 |
break; |
0 |
11289 |
break; |
0 |
| 11290 |
} |
--- |
11290 |
} |
--- |
| 11291 |
} |
--- |
11291 |
} |
--- |
| 11292 |
} |
--- |
11292 |
} |
--- |
| 11293 |
if (NewV && NewV != V) { |
0 |
11293 |
if (NewV && NewV != V) { |
0 |
| 11294 |
Worklist.push_back({{*NewV, CtxI}, S}); |
0 |
11294 |
Worklist.push_back({{*NewV, CtxI}, S}); |
0 |
| 11295 |
continue; |
0 |
11295 |
continue; |
0 |
| 11296 |
} |
--- |
11296 |
} |
--- |
| 11297 |
|
--- |
11297 |
|
--- |
| 11298 |
if (auto *CE = dyn_cast(V)) { |
0 |
11298 |
if (auto *CE = dyn_cast(V)) { |
0 |
| 11299 |
if (CE->getOpcode() == Instruction::ICmp) |
0 |
11299 |
if (CE->getOpcode() == Instruction::ICmp) |
0 |
| 11300 |
if (handleCmp(A, *CE, CE->getOperand(0), CE->getOperand(1), |
0 |
11300 |
if (handleCmp(A, *CE, CE->getOperand(0), CE->getOperand(1), |
0 |
| 11301 |
CmpInst::Predicate(CE->getPredicate()), II, Worklist)) |
0 |
11301 |
CmpInst::Predicate(CE->getPredicate()), II, Worklist)) |
0 |
| 11302 |
continue; |
0 |
11302 |
continue; |
0 |
| 11303 |
} |
--- |
11303 |
} |
--- |
| 11304 |
|
--- |
11304 |
|
--- |
| 11305 |
if (auto *I = dyn_cast(V)) { |
0 |
11305 |
if (auto *I = dyn_cast(V)) { |
0 |
| 11306 |
if (simplifyInstruction(A, *I, II, Worklist, LivenessAAs)) |
0 |
11306 |
if (simplifyInstruction(A, *I, II, Worklist, LivenessAAs)) |
0 |
| 11307 |
continue; |
0 |
11307 |
continue; |
0 |
| 11308 |
} |
--- |
11308 |
} |
--- |
| 11309 |
|
--- |
11309 |
|
--- |
| 11310 |
if (V != InitialV || isa(V)) |
0 |
11310 |
if (V != InitialV || isa(V)) |
0 |
| 11311 |
if (recurseForValue(A, IRPosition::value(*V), II.S)) |
0 |
11311 |
if (recurseForValue(A, IRPosition::value(*V), II.S)) |
0 |
| 11312 |
continue; |
0 |
11312 |
continue; |
0 |
| 11313 |
|
--- |
11313 |
|
--- |
| 11314 |
// If we haven't stripped anything we give up. |
--- |
11314 |
// If we haven't stripped anything we give up. |
--- |
| 11315 |
if (V == InitialV && CtxI == getCtxI()) { |
0 |
11315 |
if (V == InitialV && CtxI == getCtxI()) { |
0 |
| 11316 |
indicatePessimisticFixpoint(); |
0 |
11316 |
indicatePessimisticFixpoint(); |
0 |
| 11317 |
return; |
0 |
11317 |
return; |
0 |
| 11318 |
} |
--- |
11318 |
} |
--- |
| 11319 |
|
--- |
11319 |
|
--- |
| 11320 |
addValue(A, getState(), *V, CtxI, S, getAnchorScope()); |
0 |
11320 |
addValue(A, getState(), *V, CtxI, S, getAnchorScope()); |
0 |
| 11321 |
} while (!Worklist.empty()); |
0 |
11321 |
} while (!Worklist.empty()); |
0 |
| 11322 |
|
--- |
11322 |
|
--- |
| 11323 |
// If we actually used liveness information so we have to record a |
--- |
11323 |
// If we actually used liveness information so we have to record a |
--- |
| 11324 |
// dependence. |
--- |
11324 |
// dependence. |
--- |
| 11325 |
for (auto &It : LivenessAAs) |
0 |
11325 |
for (auto &It : LivenessAAs) |
0 |
| 11326 |
if (It.second.AnyDead) |
0 |
11326 |
if (It.second.AnyDead) |
0 |
| 11327 |
A.recordDependence(*It.second.LivenessAA, *this, DepClassTy::OPTIONAL); |
0 |
11327 |
A.recordDependence(*It.second.LivenessAA, *this, DepClassTy::OPTIONAL); |
0 |
| 11328 |
} |
0 |
11328 |
} |
0 |
| 11329 |
|
--- |
11329 |
|
--- |
| 11330 |
/// See AbstractAttribute::trackStatistics() |
--- |
11330 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 11331 |
void trackStatistics() const override { |
0 |
11331 |
void trackStatistics() const override { |
0 |
| 11332 |
STATS_DECLTRACK_FLOATING_ATTR(potential_values) |
0 |
11332 |
STATS_DECLTRACK_FLOATING_ATTR(potential_values) |
0 |
| 11333 |
} |
0 |
11333 |
} |
0 |
| 11334 |
}; |
--- |
11334 |
}; |
--- |
| 11335 |
|
--- |
11335 |
|
--- |
| 11336 |
struct AAPotentialValuesArgument final : AAPotentialValuesImpl { |
--- |
11336 |
struct AAPotentialValuesArgument final : AAPotentialValuesImpl { |
--- |
| 11337 |
using Base = AAPotentialValuesImpl; |
--- |
11337 |
using Base = AAPotentialValuesImpl; |
--- |
| 11338 |
AAPotentialValuesArgument(const IRPosition &IRP, Attributor &A) |
0 |
11338 |
AAPotentialValuesArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 11339 |
: Base(IRP, A) {} |
0 |
11339 |
: Base(IRP, A) {} |
0 |
| 11340 |
|
--- |
11340 |
|
--- |
| 11341 |
/// See AbstractAttribute::initialize(..). |
--- |
11341 |
/// See AbstractAttribute::initialize(..). |
--- |
| 11342 |
void initialize(Attributor &A) override { |
0 |
11342 |
void initialize(Attributor &A) override { |
0 |
| 11343 |
auto &Arg = cast(getAssociatedValue()); |
0 |
11343 |
auto &Arg = cast(getAssociatedValue()); |
0 |
| 11344 |
if (Arg.hasPointeeInMemoryValueAttr()) |
0 |
11344 |
if (Arg.hasPointeeInMemoryValueAttr()) |
0 |
| 11345 |
indicatePessimisticFixpoint(); |
0 |
11345 |
indicatePessimisticFixpoint(); |
0 |
| 11346 |
} |
0 |
11346 |
} |
0 |
| 11347 |
|
--- |
11347 |
|
--- |
| 11348 |
/// See AbstractAttribute::updateImpl(...). |
--- |
11348 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 11349 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
11349 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 11350 |
auto AssumedBefore = getAssumed(); |
0 |
11350 |
auto AssumedBefore = getAssumed(); |
0 |
| 11351 |
|
--- |
11351 |
|
--- |
| 11352 |
unsigned ArgNo = getCalleeArgNo(); |
0 |
11352 |
unsigned ArgNo = getCalleeArgNo(); |
0 |
| 11353 |
|
--- |
11353 |
|
--- |
| 11354 |
bool UsedAssumedInformation = false; |
0 |
11354 |
bool UsedAssumedInformation = false; |
0 |
| 11355 |
SmallVector Values; |
0 |
11355 |
SmallVector Values; |
0 |
| 11356 |
auto CallSitePred = [&](AbstractCallSite ACS) { |
0 |
11356 |
auto CallSitePred = [&](AbstractCallSite ACS) { |
0 |
| 11357 |
const auto CSArgIRP = IRPosition::callsite_argument(ACS, ArgNo); |
0 |
11357 |
const auto CSArgIRP = IRPosition::callsite_argument(ACS, ArgNo); |
0 |
| 11358 |
if (CSArgIRP.getPositionKind() == IRP_INVALID) |
0 |
11358 |
if (CSArgIRP.getPositionKind() == IRP_INVALID) |
0 |
| 11359 |
return false; |
0 |
11359 |
return false; |
0 |
| 11360 |
|
--- |
11360 |
|
--- |
| 11361 |
if (!A.getAssumedSimplifiedValues(CSArgIRP, this, Values, |
0 |
11361 |
if (!A.getAssumedSimplifiedValues(CSArgIRP, this, Values, |
0 |
| 11362 |
AA::Interprocedural, |
--- |
11362 |
AA::Interprocedural, |
--- |
| 11363 |
UsedAssumedInformation)) |
0 |
11363 |
UsedAssumedInformation)) |
0 |
| 11364 |
return false; |
0 |
11364 |
return false; |
0 |
| 11365 |
|
--- |
11365 |
|
--- |
| 11366 |
return isValidState(); |
0 |
11366 |
return isValidState(); |
0 |
| 11367 |
}; |
0 |
11367 |
}; |
0 |
| 11368 |
|
--- |
11368 |
|
--- |
| 11369 |
if (!A.checkForAllCallSites(CallSitePred, *this, |
0 |
11369 |
if (!A.checkForAllCallSites(CallSitePred, *this, |
0 |
| 11370 |
/* RequireAllCallSites */ true, |
--- |
11370 |
/* RequireAllCallSites */ true, |
--- |
| 11371 |
UsedAssumedInformation)) |
--- |
11371 |
UsedAssumedInformation)) |
--- |
| 11372 |
return indicatePessimisticFixpoint(); |
0 |
11372 |
return indicatePessimisticFixpoint(); |
0 |
| 11373 |
|
--- |
11373 |
|
--- |
| 11374 |
Function *Fn = getAssociatedFunction(); |
0 |
11374 |
Function *Fn = getAssociatedFunction(); |
0 |
| 11375 |
bool AnyNonLocal = false; |
0 |
11375 |
bool AnyNonLocal = false; |
0 |
| 11376 |
for (auto &It : Values) { |
0 |
11376 |
for (auto &It : Values) { |
0 |
| 11377 |
if (isa(It.getValue())) { |
0 |
11377 |
if (isa(It.getValue())) { |
0 |
| 11378 |
addValue(A, getState(), *It.getValue(), It.getCtxI(), AA::AnyScope, |
0 |
11378 |
addValue(A, getState(), *It.getValue(), It.getCtxI(), AA::AnyScope, |
0 |
| 11379 |
getAnchorScope()); |
--- |
11379 |
getAnchorScope()); |
--- |
| 11380 |
continue; |
0 |
11380 |
continue; |
0 |
| 11381 |
} |
--- |
11381 |
} |
--- |
| 11382 |
if (!AA::isDynamicallyUnique(A, *this, *It.getValue())) |
0 |
11382 |
if (!AA::isDynamicallyUnique(A, *this, *It.getValue())) |
0 |
| 11383 |
return indicatePessimisticFixpoint(); |
0 |
11383 |
return indicatePessimisticFixpoint(); |
0 |
| 11384 |
|
--- |
11384 |
|
--- |
| 11385 |
if (auto *Arg = dyn_cast(It.getValue())) |
0 |
11385 |
if (auto *Arg = dyn_cast(It.getValue())) |
0 |
| 11386 |
if (Arg->getParent() == Fn) { |
0 |
11386 |
if (Arg->getParent() == Fn) { |
0 |
| 11387 |
addValue(A, getState(), *It.getValue(), It.getCtxI(), AA::AnyScope, |
0 |
11387 |
addValue(A, getState(), *It.getValue(), It.getCtxI(), AA::AnyScope, |
0 |
| 11388 |
getAnchorScope()); |
--- |
11388 |
getAnchorScope()); |
--- |
| 11389 |
continue; |
0 |
11389 |
continue; |
0 |
| 11390 |
} |
--- |
11390 |
} |
--- |
| 11391 |
addValue(A, getState(), *It.getValue(), It.getCtxI(), AA::Interprocedural, |
0 |
11391 |
addValue(A, getState(), *It.getValue(), It.getCtxI(), AA::Interprocedural, |
0 |
| 11392 |
getAnchorScope()); |
--- |
11392 |
getAnchorScope()); |
--- |
| 11393 |
AnyNonLocal = true; |
0 |
11393 |
AnyNonLocal = true; |
0 |
| 11394 |
} |
--- |
11394 |
} |
--- |
| 11395 |
assert(!undefIsContained() && "Undef should be an explicit value!"); |
0 |
11395 |
assert(!undefIsContained() && "Undef should be an explicit value!"); |
0 |
| 11396 |
if (AnyNonLocal) |
0 |
11396 |
if (AnyNonLocal) |
0 |
| 11397 |
giveUpOnIntraprocedural(A); |
0 |
11397 |
giveUpOnIntraprocedural(A); |
0 |
| 11398 |
|
--- |
11398 |
|
--- |
| 11399 |
return (AssumedBefore == getAssumed()) ? ChangeStatus::UNCHANGED |
0 |
11399 |
return (AssumedBefore == getAssumed()) ? ChangeStatus::UNCHANGED |
0 |
| 11400 |
: ChangeStatus::CHANGED; |
0 |
11400 |
: ChangeStatus::CHANGED; |
0 |
| 11401 |
} |
0 |
11401 |
} |
0 |
| 11402 |
|
--- |
11402 |
|
--- |
| 11403 |
/// See AbstractAttribute::trackStatistics() |
--- |
11403 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 11404 |
void trackStatistics() const override { |
0 |
11404 |
void trackStatistics() const override { |
0 |
| 11405 |
STATS_DECLTRACK_ARG_ATTR(potential_values) |
0 |
11405 |
STATS_DECLTRACK_ARG_ATTR(potential_values) |
0 |
| 11406 |
} |
0 |
11406 |
} |
0 |
| 11407 |
}; |
--- |
11407 |
}; |
--- |
| 11408 |
|
--- |
11408 |
|
--- |
| 11409 |
struct AAPotentialValuesReturned : public AAPotentialValuesFloating { |
--- |
11409 |
struct AAPotentialValuesReturned : public AAPotentialValuesFloating { |
--- |
| 11410 |
using Base = AAPotentialValuesFloating; |
--- |
11410 |
using Base = AAPotentialValuesFloating; |
--- |
| 11411 |
AAPotentialValuesReturned(const IRPosition &IRP, Attributor &A) |
0 |
11411 |
AAPotentialValuesReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 11412 |
: Base(IRP, A) {} |
0 |
11412 |
: Base(IRP, A) {} |
0 |
| 11413 |
|
--- |
11413 |
|
--- |
| 11414 |
/// See AbstractAttribute::initialize(..). |
--- |
11414 |
/// See AbstractAttribute::initialize(..). |
--- |
| 11415 |
void initialize(Attributor &A) override { |
0 |
11415 |
void initialize(Attributor &A) override { |
0 |
| 11416 |
Function *F = getAssociatedFunction(); |
0 |
11416 |
Function *F = getAssociatedFunction(); |
0 |
| 11417 |
if (!F || F->isDeclaration() || F->getReturnType()->isVoidTy()) { |
0 |
11417 |
if (!F || F->isDeclaration() || F->getReturnType()->isVoidTy()) { |
0 |
| 11418 |
indicatePessimisticFixpoint(); |
0 |
11418 |
indicatePessimisticFixpoint(); |
0 |
| 11419 |
return; |
0 |
11419 |
return; |
0 |
| 11420 |
} |
--- |
11420 |
} |
--- |
| 11421 |
|
--- |
11421 |
|
--- |
| 11422 |
for (Argument &Arg : F->args()) |
0 |
11422 |
for (Argument &Arg : F->args()) |
0 |
| 11423 |
if (Arg.hasReturnedAttr()) { |
0 |
11423 |
if (Arg.hasReturnedAttr()) { |
0 |
| 11424 |
addValue(A, getState(), Arg, nullptr, AA::AnyScope, F); |
0 |
11424 |
addValue(A, getState(), Arg, nullptr, AA::AnyScope, F); |
0 |
| 11425 |
ReturnedArg = &Arg; |
0 |
11425 |
ReturnedArg = &Arg; |
0 |
| 11426 |
break; |
0 |
11426 |
break; |
0 |
| 11427 |
} |
--- |
11427 |
} |
--- |
| 11428 |
if (!A.isFunctionIPOAmendable(*F) || |
0 |
11428 |
if (!A.isFunctionIPOAmendable(*F) || |
0 |
| 11429 |
A.hasSimplificationCallback(getIRPosition())) { |
0 |
11429 |
A.hasSimplificationCallback(getIRPosition())) { |
0 |
| 11430 |
if (!ReturnedArg) |
0 |
11430 |
if (!ReturnedArg) |
0 |
| 11431 |
indicatePessimisticFixpoint(); |
0 |
11431 |
indicatePessimisticFixpoint(); |
0 |
| 11432 |
else |
--- |
11432 |
else |
--- |
| 11433 |
indicateOptimisticFixpoint(); |
0 |
11433 |
indicateOptimisticFixpoint(); |
0 |
| 11434 |
} |
--- |
11434 |
} |
--- |
| 11435 |
} |
--- |
11435 |
} |
--- |
| 11436 |
|
--- |
11436 |
|
--- |
| 11437 |
/// See AbstractAttribute::updateImpl(...). |
--- |
11437 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 11438 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
11438 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 11439 |
auto AssumedBefore = getAssumed(); |
0 |
11439 |
auto AssumedBefore = getAssumed(); |
0 |
| 11440 |
bool UsedAssumedInformation = false; |
0 |
11440 |
bool UsedAssumedInformation = false; |
0 |
| 11441 |
|
--- |
11441 |
|
--- |
| 11442 |
SmallVector Values; |
0 |
11442 |
SmallVector Values; |
0 |
| 11443 |
Function *AnchorScope = getAnchorScope(); |
0 |
11443 |
Function *AnchorScope = getAnchorScope(); |
0 |
| 11444 |
auto HandleReturnedValue = [&](Value &V, Instruction *CtxI, |
0 |
11444 |
auto HandleReturnedValue = [&](Value &V, Instruction *CtxI, |
0 |
| 11445 |
bool AddValues) { |
--- |
11445 |
bool AddValues) { |
--- |
| 11446 |
for (AA::ValueScope S : {AA::Interprocedural, AA::Intraprocedural}) { |
0 |
11446 |
for (AA::ValueScope S : {AA::Interprocedural, AA::Intraprocedural}) { |
0 |
| 11447 |
Values.clear(); |
0 |
11447 |
Values.clear(); |
0 |
| 11448 |
if (!A.getAssumedSimplifiedValues(IRPosition::value(V), this, Values, S, |
0 |
11448 |
if (!A.getAssumedSimplifiedValues(IRPosition::value(V), this, Values, S, |
0 |
| 11449 |
UsedAssumedInformation, |
0 |
11449 |
UsedAssumedInformation, |
0 |
| 11450 |
/* RecurseForSelectAndPHI */ true)) |
--- |
11450 |
/* RecurseForSelectAndPHI */ true)) |
--- |
| 11451 |
return false; |
0 |
11451 |
return false; |
0 |
| 11452 |
if (!AddValues) |
0 |
11452 |
if (!AddValues) |
0 |
| 11453 |
continue; |
0 |
11453 |
continue; |
0 |
| 11454 |
for (const AA::ValueAndContext &VAC : Values) |
0 |
11454 |
for (const AA::ValueAndContext &VAC : Values) |
0 |
| 11455 |
addValue(A, getState(), *VAC.getValue(), |
0 |
11455 |
addValue(A, getState(), *VAC.getValue(), |
0 |
| 11456 |
VAC.getCtxI() ? VAC.getCtxI() : CtxI, S, AnchorScope); |
0 |
11456 |
VAC.getCtxI() ? VAC.getCtxI() : CtxI, S, AnchorScope); |
0 |
| 11457 |
} |
--- |
11457 |
} |
--- |
| 11458 |
return true; |
0 |
11458 |
return true; |
0 |
| 11459 |
}; |
0 |
11459 |
}; |
0 |
| 11460 |
|
--- |
11460 |
|
--- |
| 11461 |
if (ReturnedArg) { |
0 |
11461 |
if (ReturnedArg) { |
0 |
| 11462 |
HandleReturnedValue(*ReturnedArg, nullptr, true); |
0 |
11462 |
HandleReturnedValue(*ReturnedArg, nullptr, true); |
0 |
| 11463 |
} else { |
--- |
11463 |
} else { |
--- |
| 11464 |
auto RetInstPred = [&](Instruction &RetI) { |
0 |
11464 |
auto RetInstPred = [&](Instruction &RetI) { |
0 |
| 11465 |
bool AddValues = true; |
0 |
11465 |
bool AddValues = true; |
0 |
| 11466 |
if (isa(RetI.getOperand(0)) || |
0 |
11466 |
if (isa(RetI.getOperand(0)) || |
0 |
| 11467 |
isa(RetI.getOperand(0))) { |
0 |
11467 |
isa(RetI.getOperand(0))) { |
0 |
| 11468 |
addValue(A, getState(), *RetI.getOperand(0), &RetI, AA::AnyScope, |
0 |
11468 |
addValue(A, getState(), *RetI.getOperand(0), &RetI, AA::AnyScope, |
0 |
| 11469 |
AnchorScope); |
0 |
11469 |
AnchorScope); |
0 |
| 11470 |
AddValues = false; |
0 |
11470 |
AddValues = false; |
0 |
| 11471 |
} |
--- |
11471 |
} |
--- |
| 11472 |
return HandleReturnedValue(*RetI.getOperand(0), &RetI, AddValues); |
0 |
11472 |
return HandleReturnedValue(*RetI.getOperand(0), &RetI, AddValues); |
0 |
| 11473 |
}; |
0 |
11473 |
}; |
0 |
| 11474 |
|
--- |
11474 |
|
--- |
| 11475 |
if (!A.checkForAllInstructions(RetInstPred, *this, {Instruction::Ret}, |
0 |
11475 |
if (!A.checkForAllInstructions(RetInstPred, *this, {Instruction::Ret}, |
0 |
| 11476 |
UsedAssumedInformation, |
--- |
11476 |
UsedAssumedInformation, |
--- |
| 11477 |
/* CheckBBLivenessOnly */ true)) |
--- |
11477 |
/* CheckBBLivenessOnly */ true)) |
--- |
| 11478 |
return indicatePessimisticFixpoint(); |
0 |
11478 |
return indicatePessimisticFixpoint(); |
0 |
| 11479 |
} |
--- |
11479 |
} |
--- |
| 11480 |
|
--- |
11480 |
|
--- |
| 11481 |
return (AssumedBefore == getAssumed()) ? ChangeStatus::UNCHANGED |
0 |
11481 |
return (AssumedBefore == getAssumed()) ? ChangeStatus::UNCHANGED |
0 |
| 11482 |
: ChangeStatus::CHANGED; |
0 |
11482 |
: ChangeStatus::CHANGED; |
0 |
| 11483 |
} |
0 |
11483 |
} |
0 |
| 11484 |
|
--- |
11484 |
|
--- |
| 11485 |
void addValue(Attributor &A, StateType &State, Value &V, |
0 |
11485 |
void addValue(Attributor &A, StateType &State, Value &V, |
0 |
| 11486 |
const Instruction *CtxI, AA::ValueScope S, |
--- |
11486 |
const Instruction *CtxI, AA::ValueScope S, |
--- |
| 11487 |
Function *AnchorScope) const override { |
--- |
11487 |
Function *AnchorScope) const override { |
--- |
| 11488 |
Function *F = getAssociatedFunction(); |
0 |
11488 |
Function *F = getAssociatedFunction(); |
0 |
| 11489 |
if (auto *CB = dyn_cast(&V)) |
0 |
11489 |
if (auto *CB = dyn_cast(&V)) |
0 |
| 11490 |
if (CB->getCalledOperand() == F) |
0 |
11490 |
if (CB->getCalledOperand() == F) |
0 |
| 11491 |
return; |
0 |
11491 |
return; |
0 |
| 11492 |
Base::addValue(A, State, V, CtxI, S, AnchorScope); |
0 |
11492 |
Base::addValue(A, State, V, CtxI, S, AnchorScope); |
0 |
| 11493 |
} |
--- |
11493 |
} |
--- |
| 11494 |
|
--- |
11494 |
|
--- |
| 11495 |
ChangeStatus manifest(Attributor &A) override { |
0 |
11495 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 11496 |
if (ReturnedArg) |
0 |
11496 |
if (ReturnedArg) |
0 |
| 11497 |
return ChangeStatus::UNCHANGED; |
0 |
11497 |
return ChangeStatus::UNCHANGED; |
0 |
| 11498 |
SmallVector Values; |
0 |
11498 |
SmallVector Values; |
0 |
| 11499 |
if (!getAssumedSimplifiedValues(A, Values, AA::ValueScope::Intraprocedural, |
0 |
11499 |
if (!getAssumedSimplifiedValues(A, Values, AA::ValueScope::Intraprocedural, |
0 |
| 11500 |
/* RecurseForSelectAndPHI */ true)) |
--- |
11500 |
/* RecurseForSelectAndPHI */ true)) |
--- |
| 11501 |
return ChangeStatus::UNCHANGED; |
0 |
11501 |
return ChangeStatus::UNCHANGED; |
0 |
| 11502 |
Value *NewVal = getSingleValue(A, *this, getIRPosition(), Values); |
0 |
11502 |
Value *NewVal = getSingleValue(A, *this, getIRPosition(), Values); |
0 |
| 11503 |
if (!NewVal) |
0 |
11503 |
if (!NewVal) |
0 |
| 11504 |
return ChangeStatus::UNCHANGED; |
0 |
11504 |
return ChangeStatus::UNCHANGED; |
0 |
| 11505 |
|
--- |
11505 |
|
--- |
| 11506 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
11506 |
ChangeStatus Changed = ChangeStatus::UNCHANGED; |
0 |
| 11507 |
if (auto *Arg = dyn_cast(NewVal)) { |
0 |
11507 |
if (auto *Arg = dyn_cast(NewVal)) { |
0 |
| 11508 |
STATS_DECLTRACK(UniqueReturnValue, FunctionReturn, |
0 |
11508 |
STATS_DECLTRACK(UniqueReturnValue, FunctionReturn, |
0 |
| 11509 |
"Number of function with unique return"); |
--- |
11509 |
"Number of function with unique return"); |
--- |
| 11510 |
Changed |= A.manifestAttrs( |
--- |
11510 |
Changed |= A.manifestAttrs( |
--- |
| 11511 |
IRPosition::argument(*Arg), |
0 |
11511 |
IRPosition::argument(*Arg), |
0 |
| 11512 |
{Attribute::get(Arg->getContext(), Attribute::Returned)}); |
0 |
11512 |
{Attribute::get(Arg->getContext(), Attribute::Returned)}); |
0 |
| 11513 |
STATS_DECLTRACK_ARG_ATTR(returned); |
0 |
11513 |
STATS_DECLTRACK_ARG_ATTR(returned); |
0 |
| 11514 |
} |
--- |
11514 |
} |
--- |
| 11515 |
|
--- |
11515 |
|
--- |
| 11516 |
auto RetInstPred = [&](Instruction &RetI) { |
0 |
11516 |
auto RetInstPred = [&](Instruction &RetI) { |
0 |
| 11517 |
Value *RetOp = RetI.getOperand(0); |
0 |
11517 |
Value *RetOp = RetI.getOperand(0); |
0 |
| 11518 |
if (isa(RetOp) || RetOp == NewVal) |
0 |
11518 |
if (isa(RetOp) || RetOp == NewVal) |
0 |
| 11519 |
return true; |
0 |
11519 |
return true; |
0 |
| 11520 |
if (AA::isValidAtPosition({*NewVal, RetI}, A.getInfoCache())) |
0 |
11520 |
if (AA::isValidAtPosition({*NewVal, RetI}, A.getInfoCache())) |
0 |
| 11521 |
if (A.changeUseAfterManifest(RetI.getOperandUse(0), *NewVal)) |
0 |
11521 |
if (A.changeUseAfterManifest(RetI.getOperandUse(0), *NewVal)) |
0 |
| 11522 |
Changed = ChangeStatus::CHANGED; |
0 |
11522 |
Changed = ChangeStatus::CHANGED; |
0 |
| 11523 |
return true; |
0 |
11523 |
return true; |
0 |
| 11524 |
}; |
0 |
11524 |
}; |
0 |
| 11525 |
bool UsedAssumedInformation = false; |
0 |
11525 |
bool UsedAssumedInformation = false; |
0 |
| 11526 |
(void)A.checkForAllInstructions(RetInstPred, *this, {Instruction::Ret}, |
0 |
11526 |
(void)A.checkForAllInstructions(RetInstPred, *this, {Instruction::Ret}, |
0 |
| 11527 |
UsedAssumedInformation, |
--- |
11527 |
UsedAssumedInformation, |
--- |
| 11528 |
/* CheckBBLivenessOnly */ true); |
--- |
11528 |
/* CheckBBLivenessOnly */ true); |
--- |
| 11529 |
return Changed; |
0 |
11529 |
return Changed; |
0 |
| 11530 |
} |
0 |
11530 |
} |
0 |
| 11531 |
|
--- |
11531 |
|
--- |
| 11532 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
11532 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
| 11533 |
return AAPotentialValues::indicatePessimisticFixpoint(); |
0 |
11533 |
return AAPotentialValues::indicatePessimisticFixpoint(); |
0 |
| 11534 |
} |
--- |
11534 |
} |
--- |
| 11535 |
|
--- |
11535 |
|
--- |
| 11536 |
/// See AbstractAttribute::trackStatistics() |
--- |
11536 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 11537 |
void trackStatistics() const override{ |
0 |
11537 |
void trackStatistics() const override{ |
0 |
| 11538 |
STATS_DECLTRACK_FNRET_ATTR(potential_values)} |
0 |
11538 |
STATS_DECLTRACK_FNRET_ATTR(potential_values)} |
0 |
| 11539 |
|
--- |
11539 |
|
--- |
| 11540 |
/// The argumented with an existing `returned` attribute. |
--- |
11540 |
/// The argumented with an existing `returned` attribute. |
--- |
| 11541 |
Argument *ReturnedArg = nullptr; |
--- |
11541 |
Argument *ReturnedArg = nullptr; |
--- |
| 11542 |
}; |
--- |
11542 |
}; |
--- |
| 11543 |
|
--- |
11543 |
|
--- |
| 11544 |
struct AAPotentialValuesFunction : AAPotentialValuesImpl { |
--- |
11544 |
struct AAPotentialValuesFunction : AAPotentialValuesImpl { |
--- |
| 11545 |
AAPotentialValuesFunction(const IRPosition &IRP, Attributor &A) |
--- |
11545 |
AAPotentialValuesFunction(const IRPosition &IRP, Attributor &A) |
--- |
| 11546 |
: AAPotentialValuesImpl(IRP, A) {} |
--- |
11546 |
: AAPotentialValuesImpl(IRP, A) {} |
--- |
| 11547 |
|
--- |
11547 |
|
--- |
| 11548 |
/// See AbstractAttribute::updateImpl(...). |
--- |
11548 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 11549 |
ChangeStatus updateImpl(Attributor &A) override { |
--- |
11549 |
ChangeStatus updateImpl(Attributor &A) override { |
--- |
| 11550 |
llvm_unreachable("AAPotentialValues(Function|CallSite)::updateImpl will " |
--- |
11550 |
llvm_unreachable("AAPotentialValues(Function|CallSite)::updateImpl will " |
--- |
| 11551 |
"not be called"); |
--- |
11551 |
"not be called"); |
--- |
| 11552 |
} |
--- |
11552 |
} |
--- |
| 11553 |
|
--- |
11553 |
|
--- |
| 11554 |
/// See AbstractAttribute::trackStatistics() |
--- |
11554 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 11555 |
void trackStatistics() const override { |
--- |
11555 |
void trackStatistics() const override { |
--- |
| 11556 |
STATS_DECLTRACK_FN_ATTR(potential_values) |
--- |
11556 |
STATS_DECLTRACK_FN_ATTR(potential_values) |
--- |
| 11557 |
} |
--- |
11557 |
} |
--- |
| 11558 |
}; |
--- |
11558 |
}; |
--- |
| 11559 |
|
--- |
11559 |
|
--- |
| 11560 |
struct AAPotentialValuesCallSite : AAPotentialValuesFunction { |
--- |
11560 |
struct AAPotentialValuesCallSite : AAPotentialValuesFunction { |
--- |
| 11561 |
AAPotentialValuesCallSite(const IRPosition &IRP, Attributor &A) |
--- |
11561 |
AAPotentialValuesCallSite(const IRPosition &IRP, Attributor &A) |
--- |
| 11562 |
: AAPotentialValuesFunction(IRP, A) {} |
--- |
11562 |
: AAPotentialValuesFunction(IRP, A) {} |
--- |
| 11563 |
|
--- |
11563 |
|
--- |
| 11564 |
/// See AbstractAttribute::trackStatistics() |
--- |
11564 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 11565 |
void trackStatistics() const override { |
--- |
11565 |
void trackStatistics() const override { |
--- |
| 11566 |
STATS_DECLTRACK_CS_ATTR(potential_values) |
--- |
11566 |
STATS_DECLTRACK_CS_ATTR(potential_values) |
--- |
| 11567 |
} |
--- |
11567 |
} |
--- |
| 11568 |
}; |
--- |
11568 |
}; |
--- |
| 11569 |
|
--- |
11569 |
|
--- |
| 11570 |
struct AAPotentialValuesCallSiteReturned : AAPotentialValuesImpl { |
--- |
11570 |
struct AAPotentialValuesCallSiteReturned : AAPotentialValuesImpl { |
--- |
| 11571 |
AAPotentialValuesCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
11571 |
AAPotentialValuesCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 11572 |
: AAPotentialValuesImpl(IRP, A) {} |
0 |
11572 |
: AAPotentialValuesImpl(IRP, A) {} |
0 |
| 11573 |
|
--- |
11573 |
|
--- |
| 11574 |
/// See AbstractAttribute::updateImpl(...). |
--- |
11574 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 11575 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
11575 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 11576 |
auto AssumedBefore = getAssumed(); |
0 |
11576 |
auto AssumedBefore = getAssumed(); |
0 |
| 11577 |
|
--- |
11577 |
|
--- |
| 11578 |
Function *Callee = getAssociatedFunction(); |
0 |
11578 |
Function *Callee = getAssociatedFunction(); |
0 |
| 11579 |
if (!Callee) |
0 |
11579 |
if (!Callee) |
0 |
| 11580 |
return indicatePessimisticFixpoint(); |
0 |
11580 |
return indicatePessimisticFixpoint(); |
0 |
| 11581 |
|
--- |
11581 |
|
--- |
| 11582 |
bool UsedAssumedInformation = false; |
0 |
11582 |
bool UsedAssumedInformation = false; |
0 |
| 11583 |
auto *CB = cast(getCtxI()); |
0 |
11583 |
auto *CB = cast(getCtxI()); |
0 |
| 11584 |
if (CB->isMustTailCall() && |
0 |
11584 |
if (CB->isMustTailCall() && |
0 |
| 11585 |
!A.isAssumedDead(IRPosition::inst(*CB), this, nullptr, |
0 |
11585 |
!A.isAssumedDead(IRPosition::inst(*CB), this, nullptr, |
0 |
| 11586 |
UsedAssumedInformation)) |
--- |
11586 |
UsedAssumedInformation)) |
--- |
| 11587 |
return indicatePessimisticFixpoint(); |
0 |
11587 |
return indicatePessimisticFixpoint(); |
0 |
| 11588 |
|
--- |
11588 |
|
--- |
| 11589 |
SmallVector Values; |
0 |
11589 |
SmallVector Values; |
0 |
| 11590 |
if (!A.getAssumedSimplifiedValues(IRPosition::returned(*Callee), this, |
0 |
11590 |
if (!A.getAssumedSimplifiedValues(IRPosition::returned(*Callee), this, |
0 |
| 11591 |
Values, AA::Intraprocedural, |
--- |
11591 |
Values, AA::Intraprocedural, |
--- |
| 11592 |
UsedAssumedInformation)) |
--- |
11592 |
UsedAssumedInformation)) |
--- |
| 11593 |
return indicatePessimisticFixpoint(); |
0 |
11593 |
return indicatePessimisticFixpoint(); |
0 |
| 11594 |
|
--- |
11594 |
|
--- |
| 11595 |
Function *Caller = CB->getCaller(); |
0 |
11595 |
Function *Caller = CB->getCaller(); |
0 |
| 11596 |
|
--- |
11596 |
|
--- |
| 11597 |
bool AnyNonLocal = false; |
0 |
11597 |
bool AnyNonLocal = false; |
0 |
| 11598 |
for (auto &It : Values) { |
0 |
11598 |
for (auto &It : Values) { |
0 |
| 11599 |
Value *V = It.getValue(); |
0 |
11599 |
Value *V = It.getValue(); |
0 |
| 11600 |
std::optional CallerV = A.translateArgumentToCallSiteContent( |
0 |
11600 |
std::optional CallerV = A.translateArgumentToCallSiteContent( |
0 |
| 11601 |
V, *CB, *this, UsedAssumedInformation); |
--- |
11601 |
V, *CB, *this, UsedAssumedInformation); |
--- |
| 11602 |
if (!CallerV.has_value()) { |
0 |
11602 |
if (!CallerV.has_value()) { |
0 |
| 11603 |
// Nothing to do as long as no value was determined. |
--- |
11603 |
// Nothing to do as long as no value was determined. |
--- |
| 11604 |
continue; |
0 |
11604 |
continue; |
0 |
| 11605 |
} |
--- |
11605 |
} |
--- |
| 11606 |
V = *CallerV ? *CallerV : V; |
0 |
11606 |
V = *CallerV ? *CallerV : V; |
0 |
| 11607 |
if (AA::isDynamicallyUnique(A, *this, *V) && |
0 |
11607 |
if (AA::isDynamicallyUnique(A, *this, *V) && |
0 |
| 11608 |
AA::isValidInScope(*V, Caller)) { |
0 |
11608 |
AA::isValidInScope(*V, Caller)) { |
0 |
| 11609 |
if (*CallerV) { |
0 |
11609 |
if (*CallerV) { |
0 |
| 11610 |
SmallVector ArgValues; |
0 |
11610 |
SmallVector ArgValues; |
0 |
| 11611 |
IRPosition IRP = IRPosition::value(*V); |
0 |
11611 |
IRPosition IRP = IRPosition::value(*V); |
0 |
| 11612 |
if (auto *Arg = dyn_cast(V)) |
0 |
11612 |
if (auto *Arg = dyn_cast(V)) |
0 |
| 11613 |
if (Arg->getParent() == CB->getCalledOperand()) |
0 |
11613 |
if (Arg->getParent() == CB->getCalledOperand()) |
0 |
| 11614 |
IRP = IRPosition::callsite_argument(*CB, Arg->getArgNo()); |
0 |
11614 |
IRP = IRPosition::callsite_argument(*CB, Arg->getArgNo()); |
0 |
| 11615 |
if (recurseForValue(A, IRP, AA::AnyScope)) |
0 |
11615 |
if (recurseForValue(A, IRP, AA::AnyScope)) |
0 |
| 11616 |
continue; |
0 |
11616 |
continue; |
0 |
| 11617 |
} |
0 |
11617 |
} |
0 |
| 11618 |
addValue(A, getState(), *V, CB, AA::AnyScope, getAnchorScope()); |
0 |
11618 |
addValue(A, getState(), *V, CB, AA::AnyScope, getAnchorScope()); |
0 |
| 11619 |
} else { |
--- |
11619 |
} else { |
--- |
| 11620 |
AnyNonLocal = true; |
0 |
11620 |
AnyNonLocal = true; |
0 |
| 11621 |
break; |
0 |
11621 |
break; |
0 |
| 11622 |
} |
--- |
11622 |
} |
--- |
| 11623 |
} |
--- |
11623 |
} |
--- |
| 11624 |
if (AnyNonLocal) { |
0 |
11624 |
if (AnyNonLocal) { |
0 |
| 11625 |
Values.clear(); |
0 |
11625 |
Values.clear(); |
0 |
| 11626 |
if (!A.getAssumedSimplifiedValues(IRPosition::returned(*Callee), this, |
0 |
11626 |
if (!A.getAssumedSimplifiedValues(IRPosition::returned(*Callee), this, |
0 |
| 11627 |
Values, AA::Interprocedural, |
--- |
11627 |
Values, AA::Interprocedural, |
--- |
| 11628 |
UsedAssumedInformation)) |
--- |
11628 |
UsedAssumedInformation)) |
--- |
| 11629 |
return indicatePessimisticFixpoint(); |
0 |
11629 |
return indicatePessimisticFixpoint(); |
0 |
| 11630 |
AnyNonLocal = false; |
0 |
11630 |
AnyNonLocal = false; |
0 |
| 11631 |
getState() = PotentialLLVMValuesState::getBestState(); |
0 |
11631 |
getState() = PotentialLLVMValuesState::getBestState(); |
0 |
| 11632 |
for (auto &It : Values) { |
0 |
11632 |
for (auto &It : Values) { |
0 |
| 11633 |
Value *V = It.getValue(); |
0 |
11633 |
Value *V = It.getValue(); |
0 |
| 11634 |
if (!AA::isDynamicallyUnique(A, *this, *V)) |
0 |
11634 |
if (!AA::isDynamicallyUnique(A, *this, *V)) |
0 |
| 11635 |
return indicatePessimisticFixpoint(); |
0 |
11635 |
return indicatePessimisticFixpoint(); |
0 |
| 11636 |
if (AA::isValidInScope(*V, Caller)) { |
0 |
11636 |
if (AA::isValidInScope(*V, Caller)) { |
0 |
| 11637 |
addValue(A, getState(), *V, CB, AA::AnyScope, getAnchorScope()); |
0 |
11637 |
addValue(A, getState(), *V, CB, AA::AnyScope, getAnchorScope()); |
0 |
| 11638 |
} else { |
--- |
11638 |
} else { |
--- |
| 11639 |
AnyNonLocal = true; |
0 |
11639 |
AnyNonLocal = true; |
0 |
| 11640 |
addValue(A, getState(), *V, CB, AA::Interprocedural, |
0 |
11640 |
addValue(A, getState(), *V, CB, AA::Interprocedural, |
0 |
| 11641 |
getAnchorScope()); |
--- |
11641 |
getAnchorScope()); |
--- |
| 11642 |
} |
--- |
11642 |
} |
--- |
| 11643 |
} |
--- |
11643 |
} |
--- |
| 11644 |
if (AnyNonLocal) |
0 |
11644 |
if (AnyNonLocal) |
0 |
| 11645 |
giveUpOnIntraprocedural(A); |
0 |
11645 |
giveUpOnIntraprocedural(A); |
0 |
| 11646 |
} |
--- |
11646 |
} |
--- |
| 11647 |
return (AssumedBefore == getAssumed()) ? ChangeStatus::UNCHANGED |
0 |
11647 |
return (AssumedBefore == getAssumed()) ? ChangeStatus::UNCHANGED |
0 |
| 11648 |
: ChangeStatus::CHANGED; |
0 |
11648 |
: ChangeStatus::CHANGED; |
0 |
| 11649 |
} |
0 |
11649 |
} |
0 |
| 11650 |
|
--- |
11650 |
|
--- |
| 11651 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
11651 |
ChangeStatus indicatePessimisticFixpoint() override { |
0 |
| 11652 |
return AAPotentialValues::indicatePessimisticFixpoint(); |
0 |
11652 |
return AAPotentialValues::indicatePessimisticFixpoint(); |
0 |
| 11653 |
} |
--- |
11653 |
} |
--- |
| 11654 |
|
--- |
11654 |
|
--- |
| 11655 |
/// See AbstractAttribute::trackStatistics() |
--- |
11655 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 11656 |
void trackStatistics() const override { |
0 |
11656 |
void trackStatistics() const override { |
0 |
| 11657 |
STATS_DECLTRACK_CSRET_ATTR(potential_values) |
0 |
11657 |
STATS_DECLTRACK_CSRET_ATTR(potential_values) |
0 |
| 11658 |
} |
0 |
11658 |
} |
0 |
| 11659 |
}; |
--- |
11659 |
}; |
--- |
| 11660 |
|
--- |
11660 |
|
--- |
| 11661 |
struct AAPotentialValuesCallSiteArgument : AAPotentialValuesFloating { |
--- |
11661 |
struct AAPotentialValuesCallSiteArgument : AAPotentialValuesFloating { |
--- |
| 11662 |
AAPotentialValuesCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
11662 |
AAPotentialValuesCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 11663 |
: AAPotentialValuesFloating(IRP, A) {} |
0 |
11663 |
: AAPotentialValuesFloating(IRP, A) {} |
0 |
| 11664 |
|
--- |
11664 |
|
--- |
| 11665 |
/// See AbstractAttribute::trackStatistics() |
--- |
11665 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 11666 |
void trackStatistics() const override { |
0 |
11666 |
void trackStatistics() const override { |
0 |
| 11667 |
STATS_DECLTRACK_CSARG_ATTR(potential_values) |
0 |
11667 |
STATS_DECLTRACK_CSARG_ATTR(potential_values) |
0 |
| 11668 |
} |
0 |
11668 |
} |
0 |
| 11669 |
}; |
--- |
11669 |
}; |
--- |
| 11670 |
} // namespace |
--- |
11670 |
} // namespace |
--- |
| 11671 |
|
--- |
11671 |
|
--- |
| 11672 |
/// ---------------------- Assumption Propagation ------------------------------ |
--- |
11672 |
/// ---------------------- Assumption Propagation ------------------------------ |
--- |
| 11673 |
namespace { |
--- |
11673 |
namespace { |
--- |
| 11674 |
struct AAAssumptionInfoImpl : public AAAssumptionInfo { |
--- |
11674 |
struct AAAssumptionInfoImpl : public AAAssumptionInfo { |
--- |
| 11675 |
AAAssumptionInfoImpl(const IRPosition &IRP, Attributor &A, |
0 |
11675 |
AAAssumptionInfoImpl(const IRPosition &IRP, Attributor &A, |
0 |
| 11676 |
const DenseSet &Known) |
--- |
11676 |
const DenseSet &Known) |
--- |
| 11677 |
: AAAssumptionInfo(IRP, A, Known) {} |
0 |
11677 |
: AAAssumptionInfo(IRP, A, Known) {} |
0 |
| 11678 |
|
--- |
11678 |
|
--- |
| 11679 |
/// See AbstractAttribute::manifest(...). |
--- |
11679 |
/// See AbstractAttribute::manifest(...). |
--- |
| 11680 |
ChangeStatus manifest(Attributor &A) override { |
0 |
11680 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 11681 |
// Don't manifest a universal set if it somehow made it here. |
--- |
11681 |
// Don't manifest a universal set if it somehow made it here. |
--- |
| 11682 |
if (getKnown().isUniversal()) |
0 |
11682 |
if (getKnown().isUniversal()) |
0 |
| 11683 |
return ChangeStatus::UNCHANGED; |
0 |
11683 |
return ChangeStatus::UNCHANGED; |
0 |
| 11684 |
|
--- |
11684 |
|
--- |
| 11685 |
const IRPosition &IRP = getIRPosition(); |
0 |
11685 |
const IRPosition &IRP = getIRPosition(); |
0 |
| 11686 |
return A.manifestAttrs( |
0 |
11686 |
return A.manifestAttrs( |
0 |
| 11687 |
IRP, |
--- |
11687 |
IRP, |
--- |
| 11688 |
Attribute::get(IRP.getAnchorValue().getContext(), AssumptionAttrKey, |
0 |
11688 |
Attribute::get(IRP.getAnchorValue().getContext(), AssumptionAttrKey, |
0 |
| 11689 |
llvm::join(getAssumed().getSet(), ",")), |
0 |
11689 |
llvm::join(getAssumed().getSet(), ",")), |
0 |
| 11690 |
/* ForceReplace */ true); |
0 |
11690 |
/* ForceReplace */ true); |
0 |
| 11691 |
} |
--- |
11691 |
} |
--- |
| 11692 |
|
--- |
11692 |
|
--- |
| 11693 |
bool hasAssumption(const StringRef Assumption) const override { |
0 |
11693 |
bool hasAssumption(const StringRef Assumption) const override { |
0 |
| 11694 |
return isValidState() && setContains(Assumption); |
0 |
11694 |
return isValidState() && setContains(Assumption); |
0 |
| 11695 |
} |
--- |
11695 |
} |
--- |
| 11696 |
|
--- |
11696 |
|
--- |
| 11697 |
/// See AbstractAttribute::getAsStr() |
--- |
11697 |
/// See AbstractAttribute::getAsStr() |
--- |
| 11698 |
const std::string getAsStr(Attributor *A) const override { |
0 |
11698 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 11699 |
const SetContents &Known = getKnown(); |
0 |
11699 |
const SetContents &Known = getKnown(); |
0 |
| 11700 |
const SetContents &Assumed = getAssumed(); |
0 |
11700 |
const SetContents &Assumed = getAssumed(); |
0 |
| 11701 |
|
--- |
11701 |
|
--- |
| 11702 |
const std::string KnownStr = |
--- |
11702 |
const std::string KnownStr = |
--- |
| 11703 |
llvm::join(Known.getSet().begin(), Known.getSet().end(), ","); |
0 |
11703 |
llvm::join(Known.getSet().begin(), Known.getSet().end(), ","); |
0 |
| 11704 |
const std::string AssumedStr = |
--- |
11704 |
const std::string AssumedStr = |
--- |
| 11705 |
(Assumed.isUniversal()) |
0 |
11705 |
(Assumed.isUniversal()) |
0 |
| 11706 |
? "Universal" |
--- |
11706 |
? "Universal" |
--- |
| 11707 |
: llvm::join(Assumed.getSet().begin(), Assumed.getSet().end(), ","); |
0 |
11707 |
: llvm::join(Assumed.getSet().begin(), Assumed.getSet().end(), ","); |
0 |
| 11708 |
|
--- |
11708 |
|
--- |
| 11709 |
return "Known [" + KnownStr + "]," + " Assumed [" + AssumedStr + "]"; |
0 |
11709 |
return "Known [" + KnownStr + "]," + " Assumed [" + AssumedStr + "]"; |
0 |
| 11710 |
} |
0 |
11710 |
} |
0 |
| 11711 |
}; |
--- |
11711 |
}; |
--- |
| 11712 |
|
--- |
11712 |
|
--- |
| 11713 |
/// Propagates assumption information from parent functions to all of their |
--- |
11713 |
/// Propagates assumption information from parent functions to all of their |
--- |
| 11714 |
/// successors. An assumption can be propagated if the containing function |
--- |
11714 |
/// successors. An assumption can be propagated if the containing function |
--- |
| 11715 |
/// dominates the called function. |
--- |
11715 |
/// dominates the called function. |
--- |
| 11716 |
/// |
--- |
11716 |
/// |
--- |
| 11717 |
/// We start with a "known" set of assumptions already valid for the associated |
--- |
11717 |
/// We start with a "known" set of assumptions already valid for the associated |
--- |
| 11718 |
/// function and an "assumed" set that initially contains all possible |
--- |
11718 |
/// function and an "assumed" set that initially contains all possible |
--- |
| 11719 |
/// assumptions. The assumed set is inter-procedurally updated by narrowing its |
--- |
11719 |
/// assumptions. The assumed set is inter-procedurally updated by narrowing its |
--- |
| 11720 |
/// contents as concrete values are known. The concrete values are seeded by the |
--- |
11720 |
/// contents as concrete values are known. The concrete values are seeded by the |
--- |
| 11721 |
/// first nodes that are either entries into the call graph, or contains no |
--- |
11721 |
/// first nodes that are either entries into the call graph, or contains no |
--- |
| 11722 |
/// assumptions. Each node is updated as the intersection of the assumed state |
--- |
11722 |
/// assumptions. Each node is updated as the intersection of the assumed state |
--- |
| 11723 |
/// with all of its predecessors. |
--- |
11723 |
/// with all of its predecessors. |
--- |
| 11724 |
struct AAAssumptionInfoFunction final : AAAssumptionInfoImpl { |
--- |
11724 |
struct AAAssumptionInfoFunction final : AAAssumptionInfoImpl { |
--- |
| 11725 |
AAAssumptionInfoFunction(const IRPosition &IRP, Attributor &A) |
0 |
11725 |
AAAssumptionInfoFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 11726 |
: AAAssumptionInfoImpl(IRP, A, |
--- |
11726 |
: AAAssumptionInfoImpl(IRP, A, |
--- |
| 11727 |
getAssumptions(*IRP.getAssociatedFunction())) {} |
0 |
11727 |
getAssumptions(*IRP.getAssociatedFunction())) {} |
0 |
| 11728 |
|
--- |
11728 |
|
--- |
| 11729 |
/// See AbstractAttribute::updateImpl(...). |
--- |
11729 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 11730 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
11730 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 11731 |
bool Changed = false; |
0 |
11731 |
bool Changed = false; |
0 |
| 11732 |
|
--- |
11732 |
|
--- |
| 11733 |
auto CallSitePred = [&](AbstractCallSite ACS) { |
0 |
11733 |
auto CallSitePred = [&](AbstractCallSite ACS) { |
0 |
| 11734 |
const auto *AssumptionAA = A.getAAFor( |
0 |
11734 |
const auto *AssumptionAA = A.getAAFor( |
0 |
| 11735 |
*this, IRPosition::callsite_function(*ACS.getInstruction()), |
0 |
11735 |
*this, IRPosition::callsite_function(*ACS.getInstruction()), |
0 |
| 11736 |
DepClassTy::REQUIRED); |
--- |
11736 |
DepClassTy::REQUIRED); |
--- |
| 11737 |
if (!AssumptionAA) |
0 |
11737 |
if (!AssumptionAA) |
0 |
| 11738 |
return false; |
0 |
11738 |
return false; |
0 |
| 11739 |
// Get the set of assumptions shared by all of this function's callers. |
--- |
11739 |
// Get the set of assumptions shared by all of this function's callers. |
--- |
| 11740 |
Changed |= getIntersection(AssumptionAA->getAssumed()); |
0 |
11740 |
Changed |= getIntersection(AssumptionAA->getAssumed()); |
0 |
| 11741 |
return !getAssumed().empty() || !getKnown().empty(); |
0 |
11741 |
return !getAssumed().empty() || !getKnown().empty(); |
0 |
| 11742 |
}; |
0 |
11742 |
}; |
0 |
| 11743 |
|
--- |
11743 |
|
--- |
| 11744 |
bool UsedAssumedInformation = false; |
0 |
11744 |
bool UsedAssumedInformation = false; |
0 |
| 11745 |
// Get the intersection of all assumptions held by this node's predecessors. |
--- |
11745 |
// Get the intersection of all assumptions held by this node's predecessors. |
--- |
| 11746 |
// If we don't know all the call sites then this is either an entry into the |
--- |
11746 |
// If we don't know all the call sites then this is either an entry into the |
--- |
| 11747 |
// call graph or an empty node. This node is known to only contain its own |
--- |
11747 |
// call graph or an empty node. This node is known to only contain its own |
--- |
| 11748 |
// assumptions and can be propagated to its successors. |
--- |
11748 |
// assumptions and can be propagated to its successors. |
--- |
| 11749 |
if (!A.checkForAllCallSites(CallSitePred, *this, true, |
0 |
11749 |
if (!A.checkForAllCallSites(CallSitePred, *this, true, |
0 |
| 11750 |
UsedAssumedInformation)) |
--- |
11750 |
UsedAssumedInformation)) |
--- |
| 11751 |
return indicatePessimisticFixpoint(); |
0 |
11751 |
return indicatePessimisticFixpoint(); |
0 |
| 11752 |
|
--- |
11752 |
|
--- |
| 11753 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
11753 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
| 11754 |
} |
--- |
11754 |
} |
--- |
| 11755 |
|
--- |
11755 |
|
--- |
| 11756 |
void trackStatistics() const override {} |
0 |
11756 |
void trackStatistics() const override {} |
0 |
| 11757 |
}; |
--- |
11757 |
}; |
--- |
| 11758 |
|
--- |
11758 |
|
--- |
| 11759 |
/// Assumption Info defined for call sites. |
--- |
11759 |
/// Assumption Info defined for call sites. |
--- |
| 11760 |
struct AAAssumptionInfoCallSite final : AAAssumptionInfoImpl { |
--- |
11760 |
struct AAAssumptionInfoCallSite final : AAAssumptionInfoImpl { |
--- |
| 11761 |
|
--- |
11761 |
|
--- |
| 11762 |
AAAssumptionInfoCallSite(const IRPosition &IRP, Attributor &A) |
0 |
11762 |
AAAssumptionInfoCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 11763 |
: AAAssumptionInfoImpl(IRP, A, getInitialAssumptions(IRP)) {} |
0 |
11763 |
: AAAssumptionInfoImpl(IRP, A, getInitialAssumptions(IRP)) {} |
0 |
| 11764 |
|
--- |
11764 |
|
--- |
| 11765 |
/// See AbstractAttribute::initialize(...). |
--- |
11765 |
/// See AbstractAttribute::initialize(...). |
--- |
| 11766 |
void initialize(Attributor &A) override { |
0 |
11766 |
void initialize(Attributor &A) override { |
0 |
| 11767 |
const IRPosition &FnPos = IRPosition::function(*getAnchorScope()); |
0 |
11767 |
const IRPosition &FnPos = IRPosition::function(*getAnchorScope()); |
0 |
| 11768 |
A.getAAFor(*this, FnPos, DepClassTy::REQUIRED); |
0 |
11768 |
A.getAAFor(*this, FnPos, DepClassTy::REQUIRED); |
0 |
| 11769 |
} |
0 |
11769 |
} |
0 |
| 11770 |
|
--- |
11770 |
|
--- |
| 11771 |
/// See AbstractAttribute::updateImpl(...). |
--- |
11771 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 11772 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
11772 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 11773 |
const IRPosition &FnPos = IRPosition::function(*getAnchorScope()); |
0 |
11773 |
const IRPosition &FnPos = IRPosition::function(*getAnchorScope()); |
0 |
| 11774 |
auto *AssumptionAA = |
--- |
11774 |
auto *AssumptionAA = |
--- |
| 11775 |
A.getAAFor(*this, FnPos, DepClassTy::REQUIRED); |
0 |
11775 |
A.getAAFor(*this, FnPos, DepClassTy::REQUIRED); |
0 |
| 11776 |
if (!AssumptionAA) |
0 |
11776 |
if (!AssumptionAA) |
0 |
| 11777 |
return indicatePessimisticFixpoint(); |
0 |
11777 |
return indicatePessimisticFixpoint(); |
0 |
| 11778 |
bool Changed = getIntersection(AssumptionAA->getAssumed()); |
0 |
11778 |
bool Changed = getIntersection(AssumptionAA->getAssumed()); |
0 |
| 11779 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
11779 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
| 11780 |
} |
--- |
11780 |
} |
--- |
| 11781 |
|
--- |
11781 |
|
--- |
| 11782 |
/// See AbstractAttribute::trackStatistics() |
--- |
11782 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 11783 |
void trackStatistics() const override {} |
0 |
11783 |
void trackStatistics() const override {} |
0 |
| 11784 |
|
--- |
11784 |
|
--- |
| 11785 |
private: |
--- |
11785 |
private: |
--- |
| 11786 |
/// Helper to initialized the known set as all the assumptions this call and |
--- |
11786 |
/// Helper to initialized the known set as all the assumptions this call and |
--- |
| 11787 |
/// the callee contain. |
--- |
11787 |
/// the callee contain. |
--- |
| 11788 |
DenseSet getInitialAssumptions(const IRPosition &IRP) { |
0 |
11788 |
DenseSet getInitialAssumptions(const IRPosition &IRP) { |
0 |
| 11789 |
const CallBase &CB = cast(IRP.getAssociatedValue()); |
0 |
11789 |
const CallBase &CB = cast(IRP.getAssociatedValue()); |
0 |
| 11790 |
auto Assumptions = getAssumptions(CB); |
0 |
11790 |
auto Assumptions = getAssumptions(CB); |
0 |
| 11791 |
if (const Function *F = CB.getCaller()) |
0 |
11791 |
if (const Function *F = CB.getCaller()) |
0 |
| 11792 |
set_union(Assumptions, getAssumptions(*F)); |
0 |
11792 |
set_union(Assumptions, getAssumptions(*F)); |
0 |
| 11793 |
if (Function *F = IRP.getAssociatedFunction()) |
0 |
11793 |
if (Function *F = IRP.getAssociatedFunction()) |
0 |
| 11794 |
set_union(Assumptions, getAssumptions(*F)); |
0 |
11794 |
set_union(Assumptions, getAssumptions(*F)); |
0 |
| 11795 |
return Assumptions; |
0 |
11795 |
return Assumptions; |
0 |
| 11796 |
} |
--- |
11796 |
} |
--- |
| 11797 |
}; |
--- |
11797 |
}; |
--- |
| 11798 |
} // namespace |
--- |
11798 |
} // namespace |
--- |
| 11799 |
|
--- |
11799 |
|
--- |
| 11800 |
AACallGraphNode *AACallEdgeIterator::operator*() const { |
0 |
11800 |
AACallGraphNode *AACallEdgeIterator::operator*() const { |
0 |
| 11801 |
return static_cast(const_cast( |
--- |
11801 |
return static_cast(const_cast( |
--- |
| 11802 |
A.getOrCreateAAFor(IRPosition::function(**I)))); |
0 |
11802 |
A.getOrCreateAAFor(IRPosition::function(**I)))); |
0 |
| 11803 |
} |
--- |
11803 |
} |
--- |
| 11804 |
|
--- |
11804 |
|
--- |
| 11805 |
void AttributorCallGraph::print() { llvm::WriteGraph(outs(), this); } |
0 |
11805 |
void AttributorCallGraph::print() { llvm::WriteGraph(outs(), this); } |
0 |
| 11806 |
|
--- |
11806 |
|
--- |
| 11807 |
/// ------------------------ UnderlyingObjects --------------------------------- |
--- |
11807 |
/// ------------------------ UnderlyingObjects --------------------------------- |
--- |
| 11808 |
|
--- |
11808 |
|
--- |
| 11809 |
namespace { |
--- |
11809 |
namespace { |
--- |
| 11810 |
struct AAUnderlyingObjectsImpl |
--- |
11810 |
struct AAUnderlyingObjectsImpl |
--- |
| 11811 |
: StateWrapper { |
--- |
11811 |
: StateWrapper { |
--- |
| 11812 |
using BaseTy = StateWrapper; |
--- |
11812 |
using BaseTy = StateWrapper; |
--- |
| 11813 |
AAUnderlyingObjectsImpl(const IRPosition &IRP, Attributor &A) : BaseTy(IRP) {} |
0 |
11813 |
AAUnderlyingObjectsImpl(const IRPosition &IRP, Attributor &A) : BaseTy(IRP) {} |
0 |
| 11814 |
|
--- |
11814 |
|
--- |
| 11815 |
/// See AbstractAttribute::getAsStr(). |
--- |
11815 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 11816 |
const std::string getAsStr(Attributor *A) const override { |
0 |
11816 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 11817 |
return std::string("UnderlyingObjects ") + |
0 |
11817 |
return std::string("UnderlyingObjects ") + |
0 |
| 11818 |
(isValidState() |
0 |
11818 |
(isValidState() |
0 |
| 11819 |
? (std::string("inter #") + |
0 |
11819 |
? (std::string("inter #") + |
0 |
| 11820 |
std::to_string(InterAssumedUnderlyingObjects.size()) + |
0 |
11820 |
std::to_string(InterAssumedUnderlyingObjects.size()) + |
0 |
| 11821 |
" objs" + std::string(", intra #") + |
0 |
11821 |
" objs" + std::string(", intra #") + |
0 |
| 11822 |
std::to_string(IntraAssumedUnderlyingObjects.size()) + |
0 |
11822 |
std::to_string(IntraAssumedUnderlyingObjects.size()) + |
0 |
| 11823 |
" objs") |
--- |
11823 |
" objs") |
--- |
| 11824 |
: ""); |
0 |
11824 |
: ""); |
0 |
| 11825 |
} |
--- |
11825 |
} |
--- |
| 11826 |
|
--- |
11826 |
|
--- |
| 11827 |
/// See AbstractAttribute::trackStatistics() |
--- |
11827 |
/// See AbstractAttribute::trackStatistics() |
--- |
| 11828 |
void trackStatistics() const override {} |
0 |
11828 |
void trackStatistics() const override {} |
0 |
| 11829 |
|
--- |
11829 |
|
--- |
| 11830 |
/// See AbstractAttribute::updateImpl(...). |
--- |
11830 |
/// See AbstractAttribute::updateImpl(...). |
--- |
| 11831 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
11831 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 11832 |
auto &Ptr = getAssociatedValue(); |
0 |
11832 |
auto &Ptr = getAssociatedValue(); |
0 |
| 11833 |
|
--- |
11833 |
|
--- |
| 11834 |
auto DoUpdate = [&](SmallSetVector &UnderlyingObjects, |
0 |
11834 |
auto DoUpdate = [&](SmallSetVector &UnderlyingObjects, |
0 |
| 11835 |
AA::ValueScope Scope) { |
--- |
11835 |
AA::ValueScope Scope) { |
--- |
| 11836 |
bool UsedAssumedInformation = false; |
0 |
11836 |
bool UsedAssumedInformation = false; |
0 |
| 11837 |
SmallPtrSet SeenObjects; |
0 |
11837 |
SmallPtrSet SeenObjects; |
0 |
| 11838 |
SmallVector Values; |
0 |
11838 |
SmallVector Values; |
0 |
| 11839 |
|
--- |
11839 |
|
--- |
| 11840 |
if (!A.getAssumedSimplifiedValues(IRPosition::value(Ptr), *this, Values, |
0 |
11840 |
if (!A.getAssumedSimplifiedValues(IRPosition::value(Ptr), *this, Values, |
0 |
| 11841 |
Scope, UsedAssumedInformation)) |
--- |
11841 |
Scope, UsedAssumedInformation)) |
--- |
| 11842 |
return UnderlyingObjects.insert(&Ptr); |
0 |
11842 |
return UnderlyingObjects.insert(&Ptr); |
0 |
| 11843 |
|
--- |
11843 |
|
--- |
| 11844 |
bool Changed = false; |
0 |
11844 |
bool Changed = false; |
0 |
| 11845 |
|
--- |
11845 |
|
--- |
| 11846 |
for (unsigned I = 0; I < Values.size(); ++I) { |
0 |
11846 |
for (unsigned I = 0; I < Values.size(); ++I) { |
0 |
| 11847 |
auto &VAC = Values[I]; |
0 |
11847 |
auto &VAC = Values[I]; |
0 |
| 11848 |
auto *Obj = VAC.getValue(); |
0 |
11848 |
auto *Obj = VAC.getValue(); |
0 |
| 11849 |
Value *UO = getUnderlyingObject(Obj); |
0 |
11849 |
Value *UO = getUnderlyingObject(Obj); |
0 |
| 11850 |
if (UO && UO != VAC.getValue() && SeenObjects.insert(UO).second) { |
0 |
11850 |
if (UO && UO != VAC.getValue() && SeenObjects.insert(UO).second) { |
0 |
| 11851 |
const auto *OtherAA = A.getAAFor( |
0 |
11851 |
const auto *OtherAA = A.getAAFor( |
0 |
| 11852 |
*this, IRPosition::value(*UO), DepClassTy::OPTIONAL); |
0 |
11852 |
*this, IRPosition::value(*UO), DepClassTy::OPTIONAL); |
0 |
| 11853 |
auto Pred = [&Values](Value &V) { |
0 |
11853 |
auto Pred = [&Values](Value &V) { |
0 |
| 11854 |
Values.emplace_back(V, nullptr); |
0 |
11854 |
Values.emplace_back(V, nullptr); |
0 |
| 11855 |
return true; |
0 |
11855 |
return true; |
0 |
| 11856 |
}; |
0 |
11856 |
}; |
0 |
| 11857 |
|
--- |
11857 |
|
--- |
| 11858 |
if (!OtherAA || !OtherAA->forallUnderlyingObjects(Pred, Scope)) |
0 |
11858 |
if (!OtherAA || !OtherAA->forallUnderlyingObjects(Pred, Scope)) |
0 |
| 11859 |
llvm_unreachable( |
0 |
11859 |
llvm_unreachable( |
0 |
| 11860 |
"The forall call should not return false at this position"); |
--- |
11860 |
"The forall call should not return false at this position"); |
--- |
| 11861 |
|
--- |
11861 |
|
--- |
| 11862 |
continue; |
0 |
11862 |
continue; |
0 |
| 11863 |
} |
0 |
11863 |
} |
0 |
| 11864 |
|
--- |
11864 |
|
--- |
| 11865 |
if (isa(Obj)) { |
0 |
11865 |
if (isa(Obj)) { |
0 |
| 11866 |
Changed |= handleIndirect(A, *Obj, UnderlyingObjects, Scope); |
0 |
11866 |
Changed |= handleIndirect(A, *Obj, UnderlyingObjects, Scope); |
0 |
| 11867 |
continue; |
0 |
11867 |
continue; |
0 |
| 11868 |
} |
--- |
11868 |
} |
--- |
| 11869 |
if (auto *PHI = dyn_cast(Obj)) { |
0 |
11869 |
if (auto *PHI = dyn_cast(Obj)) { |
0 |
| 11870 |
// Explicitly look through PHIs as we do not care about dynamically |
--- |
11870 |
// Explicitly look through PHIs as we do not care about dynamically |
--- |
| 11871 |
// uniqueness. |
--- |
11871 |
// uniqueness. |
--- |
| 11872 |
for (unsigned u = 0, e = PHI->getNumIncomingValues(); u < e; u++) { |
0 |
11872 |
for (unsigned u = 0, e = PHI->getNumIncomingValues(); u < e; u++) { |
0 |
| 11873 |
Changed |= handleIndirect(A, *PHI->getIncomingValue(u), |
0 |
11873 |
Changed |= handleIndirect(A, *PHI->getIncomingValue(u), |
0 |
| 11874 |
UnderlyingObjects, Scope); |
--- |
11874 |
UnderlyingObjects, Scope); |
--- |
| 11875 |
} |
--- |
11875 |
} |
--- |
| 11876 |
continue; |
0 |
11876 |
continue; |
0 |
| 11877 |
} |
0 |
11877 |
} |
0 |
| 11878 |
|
--- |
11878 |
|
--- |
| 11879 |
Changed |= UnderlyingObjects.insert(Obj); |
0 |
11879 |
Changed |= UnderlyingObjects.insert(Obj); |
0 |
| 11880 |
} |
--- |
11880 |
} |
--- |
| 11881 |
|
--- |
11881 |
|
--- |
| 11882 |
return Changed; |
0 |
11882 |
return Changed; |
0 |
| 11883 |
}; |
0 |
11883 |
}; |
0 |
| 11884 |
|
--- |
11884 |
|
--- |
| 11885 |
bool Changed = false; |
0 |
11885 |
bool Changed = false; |
0 |
| 11886 |
Changed |= DoUpdate(IntraAssumedUnderlyingObjects, AA::Intraprocedural); |
0 |
11886 |
Changed |= DoUpdate(IntraAssumedUnderlyingObjects, AA::Intraprocedural); |
0 |
| 11887 |
Changed |= DoUpdate(InterAssumedUnderlyingObjects, AA::Interprocedural); |
0 |
11887 |
Changed |= DoUpdate(InterAssumedUnderlyingObjects, AA::Interprocedural); |
0 |
| 11888 |
|
--- |
11888 |
|
--- |
| 11889 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
11889 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
| 11890 |
} |
--- |
11890 |
} |
--- |
| 11891 |
|
--- |
11891 |
|
--- |
| 11892 |
bool forallUnderlyingObjects( |
0 |
11892 |
bool forallUnderlyingObjects( |
0 |
| 11893 |
function_ref Pred, |
--- |
11893 |
function_ref Pred, |
--- |
| 11894 |
AA::ValueScope Scope = AA::Interprocedural) const override { |
--- |
11894 |
AA::ValueScope Scope = AA::Interprocedural) const override { |
--- |
| 11895 |
if (!isValidState()) |
0 |
11895 |
if (!isValidState()) |
0 |
| 11896 |
return Pred(getAssociatedValue()); |
0 |
11896 |
return Pred(getAssociatedValue()); |
0 |
| 11897 |
|
--- |
11897 |
|
--- |
| 11898 |
auto &AssumedUnderlyingObjects = Scope == AA::Intraprocedural |
0 |
11898 |
auto &AssumedUnderlyingObjects = Scope == AA::Intraprocedural |
0 |
| 11899 |
? IntraAssumedUnderlyingObjects |
--- |
11899 |
? IntraAssumedUnderlyingObjects |
--- |
| 11900 |
: InterAssumedUnderlyingObjects; |
--- |
11900 |
: InterAssumedUnderlyingObjects; |
--- |
| 11901 |
for (Value *Obj : AssumedUnderlyingObjects) |
0 |
11901 |
for (Value *Obj : AssumedUnderlyingObjects) |
0 |
| 11902 |
if (!Pred(*Obj)) |
0 |
11902 |
if (!Pred(*Obj)) |
0 |
| 11903 |
return false; |
0 |
11903 |
return false; |
0 |
| 11904 |
|
--- |
11904 |
|
--- |
| 11905 |
return true; |
0 |
11905 |
return true; |
0 |
| 11906 |
} |
--- |
11906 |
} |
--- |
| 11907 |
|
--- |
11907 |
|
--- |
| 11908 |
private: |
--- |
11908 |
private: |
--- |
| 11909 |
/// Handle the case where the value is not the actual underlying value, such |
--- |
11909 |
/// Handle the case where the value is not the actual underlying value, such |
--- |
| 11910 |
/// as a phi node or a select instruction. |
--- |
11910 |
/// as a phi node or a select instruction. |
--- |
| 11911 |
bool handleIndirect(Attributor &A, Value &V, |
0 |
11911 |
bool handleIndirect(Attributor &A, Value &V, |
0 |
| 11912 |
SmallSetVector &UnderlyingObjects, |
--- |
11912 |
SmallSetVector &UnderlyingObjects, |
--- |
| 11913 |
AA::ValueScope Scope) { |
--- |
11913 |
AA::ValueScope Scope) { |
--- |
| 11914 |
bool Changed = false; |
0 |
11914 |
bool Changed = false; |
0 |
| 11915 |
const auto *AA = A.getAAFor( |
0 |
11915 |
const auto *AA = A.getAAFor( |
0 |
| 11916 |
*this, IRPosition::value(V), DepClassTy::OPTIONAL); |
0 |
11916 |
*this, IRPosition::value(V), DepClassTy::OPTIONAL); |
0 |
| 11917 |
auto Pred = [&](Value &V) { |
0 |
11917 |
auto Pred = [&](Value &V) { |
0 |
| 11918 |
Changed |= UnderlyingObjects.insert(&V); |
0 |
11918 |
Changed |= UnderlyingObjects.insert(&V); |
0 |
| 11919 |
return true; |
0 |
11919 |
return true; |
0 |
| 11920 |
}; |
0 |
11920 |
}; |
0 |
| 11921 |
if (!AA || !AA->forallUnderlyingObjects(Pred, Scope)) |
0 |
11921 |
if (!AA || !AA->forallUnderlyingObjects(Pred, Scope)) |
0 |
| 11922 |
llvm_unreachable( |
0 |
11922 |
llvm_unreachable( |
0 |
| 11923 |
"The forall call should not return false at this position"); |
--- |
11923 |
"The forall call should not return false at this position"); |
--- |
| 11924 |
return Changed; |
0 |
11924 |
return Changed; |
0 |
| 11925 |
} |
--- |
11925 |
} |
--- |
| 11926 |
|
--- |
11926 |
|
--- |
| 11927 |
/// All the underlying objects collected so far via intra procedural scope. |
--- |
11927 |
/// All the underlying objects collected so far via intra procedural scope. |
--- |
| 11928 |
SmallSetVector IntraAssumedUnderlyingObjects; |
--- |
11928 |
SmallSetVector IntraAssumedUnderlyingObjects; |
--- |
| 11929 |
/// All the underlying objects collected so far via inter procedural scope. |
--- |
11929 |
/// All the underlying objects collected so far via inter procedural scope. |
--- |
| 11930 |
SmallSetVector InterAssumedUnderlyingObjects; |
--- |
11930 |
SmallSetVector InterAssumedUnderlyingObjects; |
--- |
| 11931 |
}; |
--- |
11931 |
}; |
--- |
| 11932 |
|
--- |
11932 |
|
--- |
| 11933 |
struct AAUnderlyingObjectsFloating final : AAUnderlyingObjectsImpl { |
--- |
11933 |
struct AAUnderlyingObjectsFloating final : AAUnderlyingObjectsImpl { |
--- |
| 11934 |
AAUnderlyingObjectsFloating(const IRPosition &IRP, Attributor &A) |
0 |
11934 |
AAUnderlyingObjectsFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 11935 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
11935 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
| 11936 |
}; |
--- |
11936 |
}; |
--- |
| 11937 |
|
--- |
11937 |
|
--- |
| 11938 |
struct AAUnderlyingObjectsArgument final : AAUnderlyingObjectsImpl { |
--- |
11938 |
struct AAUnderlyingObjectsArgument final : AAUnderlyingObjectsImpl { |
--- |
| 11939 |
AAUnderlyingObjectsArgument(const IRPosition &IRP, Attributor &A) |
0 |
11939 |
AAUnderlyingObjectsArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 11940 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
11940 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
| 11941 |
}; |
--- |
11941 |
}; |
--- |
| 11942 |
|
--- |
11942 |
|
--- |
| 11943 |
struct AAUnderlyingObjectsCallSite final : AAUnderlyingObjectsImpl { |
--- |
11943 |
struct AAUnderlyingObjectsCallSite final : AAUnderlyingObjectsImpl { |
--- |
| 11944 |
AAUnderlyingObjectsCallSite(const IRPosition &IRP, Attributor &A) |
0 |
11944 |
AAUnderlyingObjectsCallSite(const IRPosition &IRP, Attributor &A) |
0 |
| 11945 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
11945 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
| 11946 |
}; |
--- |
11946 |
}; |
--- |
| 11947 |
|
--- |
11947 |
|
--- |
| 11948 |
struct AAUnderlyingObjectsCallSiteArgument final : AAUnderlyingObjectsImpl { |
--- |
11948 |
struct AAUnderlyingObjectsCallSiteArgument final : AAUnderlyingObjectsImpl { |
--- |
| 11949 |
AAUnderlyingObjectsCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
11949 |
AAUnderlyingObjectsCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 11950 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
11950 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
| 11951 |
}; |
--- |
11951 |
}; |
--- |
| 11952 |
|
--- |
11952 |
|
--- |
| 11953 |
struct AAUnderlyingObjectsReturned final : AAUnderlyingObjectsImpl { |
--- |
11953 |
struct AAUnderlyingObjectsReturned final : AAUnderlyingObjectsImpl { |
--- |
| 11954 |
AAUnderlyingObjectsReturned(const IRPosition &IRP, Attributor &A) |
0 |
11954 |
AAUnderlyingObjectsReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 11955 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
11955 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
| 11956 |
}; |
--- |
11956 |
}; |
--- |
| 11957 |
|
--- |
11957 |
|
--- |
| 11958 |
struct AAUnderlyingObjectsCallSiteReturned final : AAUnderlyingObjectsImpl { |
--- |
11958 |
struct AAUnderlyingObjectsCallSiteReturned final : AAUnderlyingObjectsImpl { |
--- |
| 11959 |
AAUnderlyingObjectsCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
11959 |
AAUnderlyingObjectsCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 11960 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
11960 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
| 11961 |
}; |
--- |
11961 |
}; |
--- |
| 11962 |
|
--- |
11962 |
|
--- |
| 11963 |
struct AAUnderlyingObjectsFunction final : AAUnderlyingObjectsImpl { |
--- |
11963 |
struct AAUnderlyingObjectsFunction final : AAUnderlyingObjectsImpl { |
--- |
| 11964 |
AAUnderlyingObjectsFunction(const IRPosition &IRP, Attributor &A) |
0 |
11964 |
AAUnderlyingObjectsFunction(const IRPosition &IRP, Attributor &A) |
0 |
| 11965 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
11965 |
: AAUnderlyingObjectsImpl(IRP, A) {} |
0 |
| 11966 |
}; |
--- |
11966 |
}; |
--- |
| 11967 |
} // namespace |
--- |
11967 |
} // namespace |
--- |
| 11968 |
|
--- |
11968 |
|
--- |
| 11969 |
/// ------------------------ Address Space ------------------------------------ |
--- |
11969 |
/// ------------------------ Address Space ------------------------------------ |
--- |
| 11970 |
namespace { |
--- |
11970 |
namespace { |
--- |
| 11971 |
struct AAAddressSpaceImpl : public AAAddressSpace { |
--- |
11971 |
struct AAAddressSpaceImpl : public AAAddressSpace { |
--- |
| 11972 |
AAAddressSpaceImpl(const IRPosition &IRP, Attributor &A) |
0 |
11972 |
AAAddressSpaceImpl(const IRPosition &IRP, Attributor &A) |
0 |
| 11973 |
: AAAddressSpace(IRP, A) {} |
0 |
11973 |
: AAAddressSpace(IRP, A) {} |
0 |
| 11974 |
|
--- |
11974 |
|
--- |
| 11975 |
int32_t getAddressSpace() const override { |
0 |
11975 |
int32_t getAddressSpace() const override { |
0 |
| 11976 |
assert(isValidState() && "the AA is invalid"); |
0 |
11976 |
assert(isValidState() && "the AA is invalid"); |
0 |
| 11977 |
return AssumedAddressSpace; |
0 |
11977 |
return AssumedAddressSpace; |
0 |
| 11978 |
} |
--- |
11978 |
} |
--- |
| 11979 |
|
--- |
11979 |
|
--- |
| 11980 |
/// See AbstractAttribute::initialize(...). |
--- |
11980 |
/// See AbstractAttribute::initialize(...). |
--- |
| 11981 |
void initialize(Attributor &A) override { |
0 |
11981 |
void initialize(Attributor &A) override { |
0 |
| 11982 |
assert(getAssociatedType()->isPtrOrPtrVectorTy() && |
0 |
11982 |
assert(getAssociatedType()->isPtrOrPtrVectorTy() && |
0 |
| 11983 |
"Associated value is not a pointer"); |
--- |
11983 |
"Associated value is not a pointer"); |
--- |
| 11984 |
} |
0 |
11984 |
} |
0 |
| 11985 |
|
--- |
11985 |
|
--- |
| 11986 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
11986 |
ChangeStatus updateImpl(Attributor &A) override { |
0 |
| 11987 |
int32_t OldAddressSpace = AssumedAddressSpace; |
0 |
11987 |
int32_t OldAddressSpace = AssumedAddressSpace; |
0 |
| 11988 |
auto *AUO = A.getOrCreateAAFor(getIRPosition(), this, |
0 |
11988 |
auto *AUO = A.getOrCreateAAFor(getIRPosition(), this, |
0 |
| 11989 |
DepClassTy::REQUIRED); |
--- |
11989 |
DepClassTy::REQUIRED); |
--- |
| 11990 |
auto Pred = [&](Value &Obj) { |
0 |
11990 |
auto Pred = [&](Value &Obj) { |
0 |
| 11991 |
if (isa(&Obj)) |
0 |
11991 |
if (isa(&Obj)) |
0 |
| 11992 |
return true; |
0 |
11992 |
return true; |
0 |
| 11993 |
return takeAddressSpace(Obj.getType()->getPointerAddressSpace()); |
0 |
11993 |
return takeAddressSpace(Obj.getType()->getPointerAddressSpace()); |
0 |
| 11994 |
}; |
0 |
11994 |
}; |
0 |
| 11995 |
|
--- |
11995 |
|
--- |
| 11996 |
if (!AUO->forallUnderlyingObjects(Pred)) |
0 |
11996 |
if (!AUO->forallUnderlyingObjects(Pred)) |
0 |
| 11997 |
return indicatePessimisticFixpoint(); |
0 |
11997 |
return indicatePessimisticFixpoint(); |
0 |
| 11998 |
|
--- |
11998 |
|
--- |
| 11999 |
return OldAddressSpace == AssumedAddressSpace ? ChangeStatus::UNCHANGED |
0 |
11999 |
return OldAddressSpace == AssumedAddressSpace ? ChangeStatus::UNCHANGED |
0 |
| 12000 |
: ChangeStatus::CHANGED; |
0 |
12000 |
: ChangeStatus::CHANGED; |
0 |
| 12001 |
} |
--- |
12001 |
} |
--- |
| 12002 |
|
--- |
12002 |
|
--- |
| 12003 |
/// See AbstractAttribute::manifest(...). |
--- |
12003 |
/// See AbstractAttribute::manifest(...). |
--- |
| 12004 |
ChangeStatus manifest(Attributor &A) override { |
0 |
12004 |
ChangeStatus manifest(Attributor &A) override { |
0 |
| 12005 |
Value *AssociatedValue = &getAssociatedValue(); |
0 |
12005 |
Value *AssociatedValue = &getAssociatedValue(); |
0 |
| 12006 |
Value *OriginalValue = peelAddrspacecast(AssociatedValue); |
0 |
12006 |
Value *OriginalValue = peelAddrspacecast(AssociatedValue); |
0 |
| 12007 |
if (getAddressSpace() == NoAddressSpace || |
0 |
12007 |
if (getAddressSpace() == NoAddressSpace || |
0 |
| 12008 |
static_cast(getAddressSpace()) == |
0 |
12008 |
static_cast(getAddressSpace()) == |
0 |
| 12009 |
getAssociatedType()->getPointerAddressSpace()) |
0 |
12009 |
getAssociatedType()->getPointerAddressSpace()) |
0 |
| 12010 |
return ChangeStatus::UNCHANGED; |
0 |
12010 |
return ChangeStatus::UNCHANGED; |
0 |
| 12011 |
|
--- |
12011 |
|
--- |
| 12012 |
Type *NewPtrTy = PointerType::get(getAssociatedType()->getContext(), |
0 |
12012 |
Type *NewPtrTy = PointerType::get(getAssociatedType()->getContext(), |
0 |
| 12013 |
static_cast(getAddressSpace())); |
0 |
12013 |
static_cast(getAddressSpace())); |
0 |
| 12014 |
bool UseOriginalValue = |
--- |
12014 |
bool UseOriginalValue = |
--- |
| 12015 |
OriginalValue->getType()->getPointerAddressSpace() == |
0 |
12015 |
OriginalValue->getType()->getPointerAddressSpace() == |
0 |
| 12016 |
static_cast(getAddressSpace()); |
0 |
12016 |
static_cast(getAddressSpace()); |
0 |
| 12017 |
|
--- |
12017 |
|
--- |
| 12018 |
bool Changed = false; |
0 |
12018 |
bool Changed = false; |
0 |
| 12019 |
|
--- |
12019 |
|
--- |
| 12020 |
auto MakeChange = [&](Instruction *I, Use &U) { |
0 |
12020 |
auto MakeChange = [&](Instruction *I, Use &U) { |
0 |
| 12021 |
Changed = true; |
0 |
12021 |
Changed = true; |
0 |
| 12022 |
if (UseOriginalValue) { |
0 |
12022 |
if (UseOriginalValue) { |
0 |
| 12023 |
A.changeUseAfterManifest(U, *OriginalValue); |
0 |
12023 |
A.changeUseAfterManifest(U, *OriginalValue); |
0 |
| 12024 |
return; |
0 |
12024 |
return; |
0 |
| 12025 |
} |
--- |
12025 |
} |
--- |
| 12026 |
Instruction *CastInst = new AddrSpaceCastInst(OriginalValue, NewPtrTy); |
0 |
12026 |
Instruction *CastInst = new AddrSpaceCastInst(OriginalValue, NewPtrTy); |
0 |
| 12027 |
CastInst->insertBefore(cast(I)); |
0 |
12027 |
CastInst->insertBefore(cast(I)); |
0 |
| 12028 |
A.changeUseAfterManifest(U, *CastInst); |
0 |
12028 |
A.changeUseAfterManifest(U, *CastInst); |
0 |
| 12029 |
}; |
0 |
12029 |
}; |
0 |
| 12030 |
|
--- |
12030 |
|
--- |
| 12031 |
auto Pred = [&](const Use &U, bool &) { |
0 |
12031 |
auto Pred = [&](const Use &U, bool &) { |
0 |
| 12032 |
if (U.get() != AssociatedValue) |
0 |
12032 |
if (U.get() != AssociatedValue) |
0 |
| 12033 |
return true; |
0 |
12033 |
return true; |
0 |
| 12034 |
auto *Inst = dyn_cast(U.getUser()); |
0 |
12034 |
auto *Inst = dyn_cast(U.getUser()); |
0 |
| 12035 |
if (!Inst) |
0 |
12035 |
if (!Inst) |
0 |
| 12036 |
return true; |
0 |
12036 |
return true; |
0 |
| 12037 |
// This is a WA to make sure we only change uses from the corresponding |
--- |
12037 |
// This is a WA to make sure we only change uses from the corresponding |
--- |
| 12038 |
// CGSCC if the AA is run on CGSCC instead of the entire module. |
--- |
12038 |
// CGSCC if the AA is run on CGSCC instead of the entire module. |
--- |
| 12039 |
if (!A.isRunOn(Inst->getFunction())) |
0 |
12039 |
if (!A.isRunOn(Inst->getFunction())) |
0 |
| 12040 |
return true; |
0 |
12040 |
return true; |
0 |
| 12041 |
if (isa(Inst) || isa(Inst)) |
0 |
12041 |
if (isa(Inst) || isa(Inst)) |
0 |
| 12042 |
MakeChange(Inst, const_cast |
0 |
12042 |
MakeChange(Inst, const_cast |
0 |
| 12043 |
return true; |
0 |
12043 |
return true; |
0 |
| 12044 |
}; |
0 |
12044 |
}; |
0 |
| 12045 |
|
--- |
12045 |
|
--- |
| 12046 |
// It doesn't matter if we can't check all uses as we can simply |
--- |
12046 |
// It doesn't matter if we can't check all uses as we can simply |
--- |
| 12047 |
// conservatively ignore those that can not be visited. |
--- |
12047 |
// conservatively ignore those that can not be visited. |
--- |
| 12048 |
(void)A.checkForAllUses(Pred, *this, getAssociatedValue(), |
0 |
12048 |
(void)A.checkForAllUses(Pred, *this, getAssociatedValue(), |
0 |
| 12049 |
/* CheckBBLivenessOnly */ true); |
--- |
12049 |
/* CheckBBLivenessOnly */ true); |
--- |
| 12050 |
|
--- |
12050 |
|
--- |
| 12051 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
12051 |
return Changed ? ChangeStatus::CHANGED : ChangeStatus::UNCHANGED; |
0 |
| 12052 |
} |
--- |
12052 |
} |
--- |
| 12053 |
|
--- |
12053 |
|
--- |
| 12054 |
/// See AbstractAttribute::getAsStr(). |
--- |
12054 |
/// See AbstractAttribute::getAsStr(). |
--- |
| 12055 |
const std::string getAsStr(Attributor *A) const override { |
0 |
12055 |
const std::string getAsStr(Attributor *A) const override { |
0 |
| 12056 |
if (!isValidState()) |
0 |
12056 |
if (!isValidState()) |
0 |
| 12057 |
return "addrspace()"; |
0 |
12057 |
return "addrspace()"; |
0 |
| 12058 |
return "addrspace(" + |
0 |
12058 |
return "addrspace(" + |
0 |
| 12059 |
(AssumedAddressSpace == NoAddressSpace |
0 |
12059 |
(AssumedAddressSpace == NoAddressSpace |
0 |
| 12060 |
? "none" |
0 |
12060 |
? "none" |
0 |
| 12061 |
: std::to_string(AssumedAddressSpace)) + |
0 |
12061 |
: std::to_string(AssumedAddressSpace)) + |
0 |
| 12062 |
")"; |
0 |
12062 |
")"; |
0 |
| 12063 |
} |
--- |
12063 |
} |
--- |
| 12064 |
|
--- |
12064 |
|
--- |
| 12065 |
private: |
--- |
12065 |
private: |
--- |
| 12066 |
int32_t AssumedAddressSpace = NoAddressSpace; |
--- |
12066 |
int32_t AssumedAddressSpace = NoAddressSpace; |
--- |
| 12067 |
|
--- |
12067 |
|
--- |
| 12068 |
bool takeAddressSpace(int32_t AS) { |
0 |
12068 |
bool takeAddressSpace(int32_t AS) { |
0 |
| 12069 |
if (AssumedAddressSpace == NoAddressSpace) { |
0 |
12069 |
if (AssumedAddressSpace == NoAddressSpace) { |
0 |
| 12070 |
AssumedAddressSpace = AS; |
0 |
12070 |
AssumedAddressSpace = AS; |
0 |
| 12071 |
return true; |
0 |
12071 |
return true; |
0 |
| 12072 |
} |
--- |
12072 |
} |
--- |
| 12073 |
return AssumedAddressSpace == AS; |
0 |
12073 |
return AssumedAddressSpace == AS; |
0 |
| 12074 |
} |
--- |
12074 |
} |
--- |
| 12075 |
|
--- |
12075 |
|
--- |
| 12076 |
static Value *peelAddrspacecast(Value *V) { |
0 |
12076 |
static Value *peelAddrspacecast(Value *V) { |
0 |
| 12077 |
if (auto *I = dyn_cast(V)) |
0 |
12077 |
if (auto *I = dyn_cast(V)) |
0 |
| 12078 |
return peelAddrspacecast(I->getPointerOperand()); |
0 |
12078 |
return peelAddrspacecast(I->getPointerOperand()); |
0 |
| 12079 |
if (auto *C = dyn_cast(V)) |
0 |
12079 |
if (auto *C = dyn_cast(V)) |
0 |
| 12080 |
if (C->getOpcode() == Instruction::AddrSpaceCast) |
0 |
12080 |
if (C->getOpcode() == Instruction::AddrSpaceCast) |
0 |
| 12081 |
return peelAddrspacecast(C->getOperand(0)); |
0 |
12081 |
return peelAddrspacecast(C->getOperand(0)); |
0 |
| 12082 |
return V; |
0 |
12082 |
return V; |
0 |
| 12083 |
} |
--- |
12083 |
} |
--- |
| 12084 |
}; |
--- |
12084 |
}; |
--- |
| 12085 |
|
--- |
12085 |
|
--- |
| 12086 |
struct AAAddressSpaceFloating final : AAAddressSpaceImpl { |
--- |
12086 |
struct AAAddressSpaceFloating final : AAAddressSpaceImpl { |
--- |
| 12087 |
AAAddressSpaceFloating(const IRPosition &IRP, Attributor &A) |
0 |
12087 |
AAAddressSpaceFloating(const IRPosition &IRP, Attributor &A) |
0 |
| 12088 |
: AAAddressSpaceImpl(IRP, A) {} |
0 |
12088 |
: AAAddressSpaceImpl(IRP, A) {} |
0 |
| 12089 |
|
--- |
12089 |
|
--- |
| 12090 |
void trackStatistics() const override { |
0 |
12090 |
void trackStatistics() const override { |
0 |
| 12091 |
STATS_DECLTRACK_FLOATING_ATTR(addrspace); |
0 |
12091 |
STATS_DECLTRACK_FLOATING_ATTR(addrspace); |
0 |
| 12092 |
} |
0 |
12092 |
} |
0 |
| 12093 |
}; |
--- |
12093 |
}; |
--- |
| 12094 |
|
--- |
12094 |
|
--- |
| 12095 |
struct AAAddressSpaceReturned final : AAAddressSpaceImpl { |
--- |
12095 |
struct AAAddressSpaceReturned final : AAAddressSpaceImpl { |
--- |
| 12096 |
AAAddressSpaceReturned(const IRPosition &IRP, Attributor &A) |
0 |
12096 |
AAAddressSpaceReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 12097 |
: AAAddressSpaceImpl(IRP, A) {} |
0 |
12097 |
: AAAddressSpaceImpl(IRP, A) {} |
0 |
| 12098 |
|
--- |
12098 |
|
--- |
| 12099 |
/// See AbstractAttribute::initialize(...). |
--- |
12099 |
/// See AbstractAttribute::initialize(...). |
--- |
| 12100 |
void initialize(Attributor &A) override { |
0 |
12100 |
void initialize(Attributor &A) override { |
0 |
| 12101 |
// TODO: we don't rewrite function argument for now because it will need to |
--- |
12101 |
// TODO: we don't rewrite function argument for now because it will need to |
--- |
| 12102 |
// rewrite the function signature and all call sites. |
--- |
12102 |
// rewrite the function signature and all call sites. |
--- |
| 12103 |
(void)indicatePessimisticFixpoint(); |
0 |
12103 |
(void)indicatePessimisticFixpoint(); |
0 |
| 12104 |
} |
0 |
12104 |
} |
0 |
| 12105 |
|
--- |
12105 |
|
--- |
| 12106 |
void trackStatistics() const override { |
0 |
12106 |
void trackStatistics() const override { |
0 |
| 12107 |
STATS_DECLTRACK_FNRET_ATTR(addrspace); |
0 |
12107 |
STATS_DECLTRACK_FNRET_ATTR(addrspace); |
0 |
| 12108 |
} |
0 |
12108 |
} |
0 |
| 12109 |
}; |
--- |
12109 |
}; |
--- |
| 12110 |
|
--- |
12110 |
|
--- |
| 12111 |
struct AAAddressSpaceCallSiteReturned final : AAAddressSpaceImpl { |
--- |
12111 |
struct AAAddressSpaceCallSiteReturned final : AAAddressSpaceImpl { |
--- |
| 12112 |
AAAddressSpaceCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
12112 |
AAAddressSpaceCallSiteReturned(const IRPosition &IRP, Attributor &A) |
0 |
| 12113 |
: AAAddressSpaceImpl(IRP, A) {} |
0 |
12113 |
: AAAddressSpaceImpl(IRP, A) {} |
0 |
| 12114 |
|
--- |
12114 |
|
--- |
| 12115 |
void trackStatistics() const override { |
0 |
12115 |
void trackStatistics() const override { |
0 |
| 12116 |
STATS_DECLTRACK_CSRET_ATTR(addrspace); |
0 |
12116 |
STATS_DECLTRACK_CSRET_ATTR(addrspace); |
0 |
| 12117 |
} |
0 |
12117 |
} |
0 |
| 12118 |
}; |
--- |
12118 |
}; |
--- |
| 12119 |
|
--- |
12119 |
|
--- |
| 12120 |
struct AAAddressSpaceArgument final : AAAddressSpaceImpl { |
--- |
12120 |
struct AAAddressSpaceArgument final : AAAddressSpaceImpl { |
--- |
| 12121 |
AAAddressSpaceArgument(const IRPosition &IRP, Attributor &A) |
0 |
12121 |
AAAddressSpaceArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 12122 |
: AAAddressSpaceImpl(IRP, A) {} |
0 |
12122 |
: AAAddressSpaceImpl(IRP, A) {} |
0 |
| 12123 |
|
--- |
12123 |
|
--- |
| 12124 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(addrspace); } |
0 |
12124 |
void trackStatistics() const override { STATS_DECLTRACK_ARG_ATTR(addrspace); } |
0 |
| 12125 |
}; |
--- |
12125 |
}; |
--- |
| 12126 |
|
--- |
12126 |
|
--- |
| 12127 |
struct AAAddressSpaceCallSiteArgument final : AAAddressSpaceImpl { |
--- |
12127 |
struct AAAddressSpaceCallSiteArgument final : AAAddressSpaceImpl { |
--- |
| 12128 |
AAAddressSpaceCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
12128 |
AAAddressSpaceCallSiteArgument(const IRPosition &IRP, Attributor &A) |
0 |
| 12129 |
: AAAddressSpaceImpl(IRP, A) {} |
0 |
12129 |
: AAAddressSpaceImpl(IRP, A) {} |
0 |
| 12130 |
|
--- |
12130 |
|
--- |
| 12131 |
/// See AbstractAttribute::initialize(...). |
--- |
12131 |
/// See AbstractAttribute::initialize(...). |
--- |
| 12132 |
void initialize(Attributor &A) override { |
0 |
12132 |
void initialize(Attributor &A) override { |
0 |
| 12133 |
// TODO: we don't rewrite call site argument for now because it will need to |
--- |
12133 |
// TODO: we don't rewrite call site argument for now because it will need to |
--- |
| 12134 |
// rewrite the function signature of the callee. |
--- |
12134 |
// rewrite the function signature of the callee. |
--- |
| 12135 |
(void)indicatePessimisticFixpoint(); |
0 |
12135 |
(void)indicatePessimisticFixpoint(); |
0 |
| 12136 |
} |
0 |
12136 |
} |
0 |
| 12137 |
|
--- |
12137 |
|
--- |
| 12138 |
void trackStatistics() const override { |
0 |
12138 |
void trackStatistics() const override { |
0 |
| 12139 |
STATS_DECLTRACK_CSARG_ATTR(addrspace); |
0 |
12139 |
STATS_DECLTRACK_CSARG_ATTR(addrspace); |
0 |
| 12140 |
} |
0 |
12140 |
} |
0 |
| 12141 |
}; |
--- |
12141 |
}; |
--- |
| 12142 |
} // namespace |
--- |
12142 |
} // namespace |
--- |
| 12143 |
|
--- |
12143 |
|
--- |
| 12144 |
const char AANoUnwind::ID = 0; |
--- |
12144 |
const char AANoUnwind::ID = 0; |
--- |
| 12145 |
const char AANoSync::ID = 0; |
--- |
12145 |
const char AANoSync::ID = 0; |
--- |
| 12146 |
const char AANoFree::ID = 0; |
--- |
12146 |
const char AANoFree::ID = 0; |
--- |
| 12147 |
const char AANonNull::ID = 0; |
--- |
12147 |
const char AANonNull::ID = 0; |
--- |
| 12148 |
const char AAMustProgress::ID = 0; |
--- |
12148 |
const char AAMustProgress::ID = 0; |
--- |
| 12149 |
const char AANoRecurse::ID = 0; |
--- |
12149 |
const char AANoRecurse::ID = 0; |
--- |
| 12150 |
const char AANonConvergent::ID = 0; |
--- |
12150 |
const char AANonConvergent::ID = 0; |
--- |
| 12151 |
const char AAWillReturn::ID = 0; |
--- |
12151 |
const char AAWillReturn::ID = 0; |
--- |
| 12152 |
const char AAUndefinedBehavior::ID = 0; |
--- |
12152 |
const char AAUndefinedBehavior::ID = 0; |
--- |
| 12153 |
const char AANoAlias::ID = 0; |
--- |
12153 |
const char AANoAlias::ID = 0; |
--- |
| 12154 |
const char AAIntraFnReachability::ID = 0; |
--- |
12154 |
const char AAIntraFnReachability::ID = 0; |
--- |
| 12155 |
const char AANoReturn::ID = 0; |
--- |
12155 |
const char AANoReturn::ID = 0; |
--- |
| 12156 |
const char AAIsDead::ID = 0; |
--- |
12156 |
const char AAIsDead::ID = 0; |
--- |
| 12157 |
const char AADereferenceable::ID = 0; |
--- |
12157 |
const char AADereferenceable::ID = 0; |
--- |
| 12158 |
const char AAAlign::ID = 0; |
--- |
12158 |
const char AAAlign::ID = 0; |
--- |
| 12159 |
const char AAInstanceInfo::ID = 0; |
--- |
12159 |
const char AAInstanceInfo::ID = 0; |
--- |
| 12160 |
const char AANoCapture::ID = 0; |
--- |
12160 |
const char AANoCapture::ID = 0; |
--- |
| 12161 |
const char AAValueSimplify::ID = 0; |
--- |
12161 |
const char AAValueSimplify::ID = 0; |
--- |
| 12162 |
const char AAHeapToStack::ID = 0; |
--- |
12162 |
const char AAHeapToStack::ID = 0; |
--- |
| 12163 |
const char AAPrivatizablePtr::ID = 0; |
--- |
12163 |
const char AAPrivatizablePtr::ID = 0; |
--- |
| 12164 |
const char AAMemoryBehavior::ID = 0; |
--- |
12164 |
const char AAMemoryBehavior::ID = 0; |
--- |
| 12165 |
const char AAMemoryLocation::ID = 0; |
--- |
12165 |
const char AAMemoryLocation::ID = 0; |
--- |
| 12166 |
const char AAValueConstantRange::ID = 0; |
--- |
12166 |
const char AAValueConstantRange::ID = 0; |
--- |
| 12167 |
const char AAPotentialConstantValues::ID = 0; |
--- |
12167 |
const char AAPotentialConstantValues::ID = 0; |
--- |
| 12168 |
const char AAPotentialValues::ID = 0; |
--- |
12168 |
const char AAPotentialValues::ID = 0; |
--- |
| 12169 |
const char AANoUndef::ID = 0; |
--- |
12169 |
const char AANoUndef::ID = 0; |
--- |
| 12170 |
const char AANoFPClass::ID = 0; |
--- |
12170 |
const char AANoFPClass::ID = 0; |
--- |
| 12171 |
const char AACallEdges::ID = 0; |
--- |
12171 |
const char AACallEdges::ID = 0; |
--- |
| 12172 |
const char AAInterFnReachability::ID = 0; |
--- |
12172 |
const char AAInterFnReachability::ID = 0; |
--- |
| 12173 |
const char AAPointerInfo::ID = 0; |
--- |
12173 |
const char AAPointerInfo::ID = 0; |
--- |
| 12174 |
const char AAAssumptionInfo::ID = 0; |
--- |
12174 |
const char AAAssumptionInfo::ID = 0; |
--- |
| 12175 |
const char AAUnderlyingObjects::ID = 0; |
--- |
12175 |
const char AAUnderlyingObjects::ID = 0; |
--- |
| 12176 |
const char AAAddressSpace::ID = 0; |
--- |
12176 |
const char AAAddressSpace::ID = 0; |
--- |
| 12177 |
|
--- |
12177 |
|
--- |
| 12178 |
// Macro magic to create the static generator function for attributes that |
--- |
12178 |
// Macro magic to create the static generator function for attributes that |
--- |
| 12179 |
// follow the naming scheme. |
--- |
12179 |
// follow the naming scheme. |
--- |
| 12180 |
|
--- |
12180 |
|
--- |
| 12181 |
#define SWITCH_PK_INV(CLASS, PK, POS_NAME) \ |
--- |
12181 |
#define SWITCH_PK_INV(CLASS, PK, POS_NAME) \ |
--- |
| 12182 |
case IRPosition::PK: \ |
--- |
12182 |
case IRPosition::PK: \ |
--- |
| 12183 |
llvm_unreachable("Cannot create " #CLASS " for a " POS_NAME " position!"); |
--- |
12183 |
llvm_unreachable("Cannot create " #CLASS " for a " POS_NAME " position!"); |
--- |
| 12184 |
|
--- |
12184 |
|
--- |
| 12185 |
#define SWITCH_PK_CREATE(CLASS, IRP, PK, SUFFIX) \ |
--- |
12185 |
#define SWITCH_PK_CREATE(CLASS, IRP, PK, SUFFIX) \ |
--- |
| 12186 |
case IRPosition::PK: \ |
--- |
12186 |
case IRPosition::PK: \ |
--- |
| 12187 |
AA = new (A.Allocator) CLASS##SUFFIX(IRP, A); \ |
--- |
12187 |
AA = new (A.Allocator) CLASS##SUFFIX(IRP, A); \ |
--- |
| 12188 |
++NumAAs; \ |
--- |
12188 |
++NumAAs; \ |
--- |
| 12189 |
break; |
--- |
12189 |
break; |
--- |
| 12190 |
|
--- |
12190 |
|
--- |
| 12191 |
#define CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(CLASS) \ |
--- |
12191 |
#define CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(CLASS) \ |
--- |
| 12192 |
CLASS &CLASS::createForPosition(const IRPosition &IRP, Attributor &A) { \ |
--- |
12192 |
CLASS &CLASS::createForPosition(const IRPosition &IRP, Attributor &A) { \ |
--- |
| 12193 |
CLASS *AA = nullptr; \ |
--- |
12193 |
CLASS *AA = nullptr; \ |
--- |
| 12194 |
switch (IRP.getPositionKind()) { \ |
--- |
12194 |
switch (IRP.getPositionKind()) { \ |
--- |
| 12195 |
SWITCH_PK_INV(CLASS, IRP_INVALID, "invalid") \ |
--- |
12195 |
SWITCH_PK_INV(CLASS, IRP_INVALID, "invalid") \ |
--- |
| 12196 |
SWITCH_PK_INV(CLASS, IRP_FLOAT, "floating") \ |
--- |
12196 |
SWITCH_PK_INV(CLASS, IRP_FLOAT, "floating") \ |
--- |
| 12197 |
SWITCH_PK_INV(CLASS, IRP_ARGUMENT, "argument") \ |
--- |
12197 |
SWITCH_PK_INV(CLASS, IRP_ARGUMENT, "argument") \ |
--- |
| 12198 |
SWITCH_PK_INV(CLASS, IRP_RETURNED, "returned") \ |
--- |
12198 |
SWITCH_PK_INV(CLASS, IRP_RETURNED, "returned") \ |
--- |
| 12199 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE_RETURNED, "call site returned") \ |
--- |
12199 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE_RETURNED, "call site returned") \ |
--- |
| 12200 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE_ARGUMENT, "call site argument") \ |
--- |
12200 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE_ARGUMENT, "call site argument") \ |
--- |
| 12201 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FUNCTION, Function) \ |
--- |
12201 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FUNCTION, Function) \ |
--- |
| 12202 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE, CallSite) \ |
--- |
12202 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE, CallSite) \ |
--- |
| 12203 |
} \ |
--- |
12203 |
} \ |
--- |
| 12204 |
return *AA; \ |
--- |
12204 |
return *AA; \ |
--- |
| 12205 |
} |
--- |
12205 |
} |
--- |
| 12206 |
|
--- |
12206 |
|
--- |
| 12207 |
#define CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(CLASS) \ |
--- |
12207 |
#define CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(CLASS) \ |
--- |
| 12208 |
CLASS &CLASS::createForPosition(const IRPosition &IRP, Attributor &A) { \ |
--- |
12208 |
CLASS &CLASS::createForPosition(const IRPosition &IRP, Attributor &A) { \ |
--- |
| 12209 |
CLASS *AA = nullptr; \ |
--- |
12209 |
CLASS *AA = nullptr; \ |
--- |
| 12210 |
switch (IRP.getPositionKind()) { \ |
--- |
12210 |
switch (IRP.getPositionKind()) { \ |
--- |
| 12211 |
SWITCH_PK_INV(CLASS, IRP_INVALID, "invalid") \ |
--- |
12211 |
SWITCH_PK_INV(CLASS, IRP_INVALID, "invalid") \ |
--- |
| 12212 |
SWITCH_PK_INV(CLASS, IRP_FUNCTION, "function") \ |
--- |
12212 |
SWITCH_PK_INV(CLASS, IRP_FUNCTION, "function") \ |
--- |
| 12213 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE, "call site") \ |
--- |
12213 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE, "call site") \ |
--- |
| 12214 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FLOAT, Floating) \ |
--- |
12214 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FLOAT, Floating) \ |
--- |
| 12215 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_ARGUMENT, Argument) \ |
--- |
12215 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_ARGUMENT, Argument) \ |
--- |
| 12216 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_RETURNED, Returned) \ |
--- |
12216 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_RETURNED, Returned) \ |
--- |
| 12217 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_RETURNED, CallSiteReturned) \ |
--- |
12217 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_RETURNED, CallSiteReturned) \ |
--- |
| 12218 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_ARGUMENT, CallSiteArgument) \ |
--- |
12218 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_ARGUMENT, CallSiteArgument) \ |
--- |
| 12219 |
} \ |
--- |
12219 |
} \ |
--- |
| 12220 |
return *AA; \ |
--- |
12220 |
return *AA; \ |
--- |
| 12221 |
} |
--- |
12221 |
} |
--- |
| 12222 |
|
--- |
12222 |
|
--- |
| 12223 |
#define CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION(CLASS) \ |
--- |
12223 |
#define CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION(CLASS) \ |
--- |
| 12224 |
CLASS &CLASS::createForPosition(const IRPosition &IRP, Attributor &A) { \ |
--- |
12224 |
CLASS &CLASS::createForPosition(const IRPosition &IRP, Attributor &A) { \ |
--- |
| 12225 |
CLASS *AA = nullptr; \ |
--- |
12225 |
CLASS *AA = nullptr; \ |
--- |
| 12226 |
switch (IRP.getPositionKind()) { \ |
--- |
12226 |
switch (IRP.getPositionKind()) { \ |
--- |
| 12227 |
SWITCH_PK_INV(CLASS, IRP_INVALID, "invalid") \ |
--- |
12227 |
SWITCH_PK_INV(CLASS, IRP_INVALID, "invalid") \ |
--- |
| 12228 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FUNCTION, Function) \ |
--- |
12228 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FUNCTION, Function) \ |
--- |
| 12229 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE, CallSite) \ |
--- |
12229 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE, CallSite) \ |
--- |
| 12230 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FLOAT, Floating) \ |
--- |
12230 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FLOAT, Floating) \ |
--- |
| 12231 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_ARGUMENT, Argument) \ |
--- |
12231 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_ARGUMENT, Argument) \ |
--- |
| 12232 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_RETURNED, Returned) \ |
--- |
12232 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_RETURNED, Returned) \ |
--- |
| 12233 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_RETURNED, CallSiteReturned) \ |
--- |
12233 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_RETURNED, CallSiteReturned) \ |
--- |
| 12234 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_ARGUMENT, CallSiteArgument) \ |
--- |
12234 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_ARGUMENT, CallSiteArgument) \ |
--- |
| 12235 |
} \ |
--- |
12235 |
} \ |
--- |
| 12236 |
return *AA; \ |
--- |
12236 |
return *AA; \ |
--- |
| 12237 |
} |
--- |
12237 |
} |
--- |
| 12238 |
|
--- |
12238 |
|
--- |
| 12239 |
#define CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(CLASS) \ |
--- |
12239 |
#define CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(CLASS) \ |
--- |
| 12240 |
CLASS &CLASS::createForPosition(const IRPosition &IRP, Attributor &A) { \ |
--- |
12240 |
CLASS &CLASS::createForPosition(const IRPosition &IRP, Attributor &A) { \ |
--- |
| 12241 |
CLASS *AA = nullptr; \ |
--- |
12241 |
CLASS *AA = nullptr; \ |
--- |
| 12242 |
switch (IRP.getPositionKind()) { \ |
--- |
12242 |
switch (IRP.getPositionKind()) { \ |
--- |
| 12243 |
SWITCH_PK_INV(CLASS, IRP_INVALID, "invalid") \ |
--- |
12243 |
SWITCH_PK_INV(CLASS, IRP_INVALID, "invalid") \ |
--- |
| 12244 |
SWITCH_PK_INV(CLASS, IRP_ARGUMENT, "argument") \ |
--- |
12244 |
SWITCH_PK_INV(CLASS, IRP_ARGUMENT, "argument") \ |
--- |
| 12245 |
SWITCH_PK_INV(CLASS, IRP_FLOAT, "floating") \ |
--- |
12245 |
SWITCH_PK_INV(CLASS, IRP_FLOAT, "floating") \ |
--- |
| 12246 |
SWITCH_PK_INV(CLASS, IRP_RETURNED, "returned") \ |
--- |
12246 |
SWITCH_PK_INV(CLASS, IRP_RETURNED, "returned") \ |
--- |
| 12247 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE_RETURNED, "call site returned") \ |
--- |
12247 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE_RETURNED, "call site returned") \ |
--- |
| 12248 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE_ARGUMENT, "call site argument") \ |
--- |
12248 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE_ARGUMENT, "call site argument") \ |
--- |
| 12249 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE, "call site") \ |
--- |
12249 |
SWITCH_PK_INV(CLASS, IRP_CALL_SITE, "call site") \ |
--- |
| 12250 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FUNCTION, Function) \ |
--- |
12250 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FUNCTION, Function) \ |
--- |
| 12251 |
} \ |
--- |
12251 |
} \ |
--- |
| 12252 |
return *AA; \ |
--- |
12252 |
return *AA; \ |
--- |
| 12253 |
} |
--- |
12253 |
} |
--- |
| 12254 |
|
--- |
12254 |
|
--- |
| 12255 |
#define CREATE_NON_RET_ABSTRACT_ATTRIBUTE_FOR_POSITION(CLASS) \ |
--- |
12255 |
#define CREATE_NON_RET_ABSTRACT_ATTRIBUTE_FOR_POSITION(CLASS) \ |
--- |
| 12256 |
CLASS &CLASS::createForPosition(const IRPosition &IRP, Attributor &A) { \ |
--- |
12256 |
CLASS &CLASS::createForPosition(const IRPosition &IRP, Attributor &A) { \ |
--- |
| 12257 |
CLASS *AA = nullptr; \ |
--- |
12257 |
CLASS *AA = nullptr; \ |
--- |
| 12258 |
switch (IRP.getPositionKind()) { \ |
--- |
12258 |
switch (IRP.getPositionKind()) { \ |
--- |
| 12259 |
SWITCH_PK_INV(CLASS, IRP_INVALID, "invalid") \ |
--- |
12259 |
SWITCH_PK_INV(CLASS, IRP_INVALID, "invalid") \ |
--- |
| 12260 |
SWITCH_PK_INV(CLASS, IRP_RETURNED, "returned") \ |
--- |
12260 |
SWITCH_PK_INV(CLASS, IRP_RETURNED, "returned") \ |
--- |
| 12261 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FUNCTION, Function) \ |
--- |
12261 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FUNCTION, Function) \ |
--- |
| 12262 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE, CallSite) \ |
--- |
12262 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE, CallSite) \ |
--- |
| 12263 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FLOAT, Floating) \ |
--- |
12263 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_FLOAT, Floating) \ |
--- |
| 12264 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_ARGUMENT, Argument) \ |
--- |
12264 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_ARGUMENT, Argument) \ |
--- |
| 12265 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_RETURNED, CallSiteReturned) \ |
--- |
12265 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_RETURNED, CallSiteReturned) \ |
--- |
| 12266 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_ARGUMENT, CallSiteArgument) \ |
--- |
12266 |
SWITCH_PK_CREATE(CLASS, IRP, IRP_CALL_SITE_ARGUMENT, CallSiteArgument) \ |
--- |
| 12267 |
} \ |
--- |
12267 |
} \ |
--- |
| 12268 |
return *AA; \ |
--- |
12268 |
return *AA; \ |
--- |
| 12269 |
} |
--- |
12269 |
} |
--- |
| 12270 |
|
--- |
12270 |
|
--- |
| 12271 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoUnwind) |
0 |
12271 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoUnwind) |
0 |
| 12272 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoSync) |
0 |
12272 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoSync) |
0 |
| 12273 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoRecurse) |
0 |
12273 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoRecurse) |
0 |
| 12274 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAWillReturn) |
0 |
12274 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAWillReturn) |
0 |
| 12275 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoReturn) |
0 |
12275 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoReturn) |
0 |
| 12276 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAMemoryLocation) |
0 |
12276 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAMemoryLocation) |
0 |
| 12277 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AACallEdges) |
0 |
12277 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AACallEdges) |
0 |
| 12278 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAAssumptionInfo) |
0 |
12278 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAAssumptionInfo) |
0 |
| 12279 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAMustProgress) |
0 |
12279 |
CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAMustProgress) |
0 |
| 12280 |
|
--- |
12280 |
|
--- |
| 12281 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANonNull) |
0 |
12281 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANonNull) |
0 |
| 12282 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoAlias) |
0 |
12282 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoAlias) |
0 |
| 12283 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAPrivatizablePtr) |
0 |
12283 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAPrivatizablePtr) |
0 |
| 12284 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AADereferenceable) |
0 |
12284 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AADereferenceable) |
0 |
| 12285 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAAlign) |
0 |
12285 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAAlign) |
0 |
| 12286 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAInstanceInfo) |
0 |
12286 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAInstanceInfo) |
0 |
| 12287 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoCapture) |
0 |
12287 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoCapture) |
0 |
| 12288 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAValueConstantRange) |
0 |
12288 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAValueConstantRange) |
0 |
| 12289 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAPotentialConstantValues) |
0 |
12289 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAPotentialConstantValues) |
0 |
| 12290 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAPotentialValues) |
0 |
12290 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAPotentialValues) |
0 |
| 12291 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoUndef) |
0 |
12291 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoUndef) |
0 |
| 12292 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoFPClass) |
0 |
12292 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoFPClass) |
0 |
| 12293 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAPointerInfo) |
0 |
12293 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAPointerInfo) |
0 |
| 12294 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAAddressSpace) |
0 |
12294 |
CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAAddressSpace) |
0 |
| 12295 |
|
--- |
12295 |
|
--- |
| 12296 |
CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAValueSimplify) |
0 |
12296 |
CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAValueSimplify) |
0 |
| 12297 |
CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAIsDead) |
0 |
12297 |
CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAIsDead) |
0 |
| 12298 |
CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoFree) |
0 |
12298 |
CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANoFree) |
0 |
| 12299 |
CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAUnderlyingObjects) |
0 |
12299 |
CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAUnderlyingObjects) |
0 |
| 12300 |
|
--- |
12300 |
|
--- |
| 12301 |
CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAHeapToStack) |
0 |
12301 |
CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAHeapToStack) |
0 |
| 12302 |
CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAUndefinedBehavior) |
0 |
12302 |
CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAUndefinedBehavior) |
0 |
| 12303 |
CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANonConvergent) |
0 |
12303 |
CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AANonConvergent) |
0 |
| 12304 |
CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAIntraFnReachability) |
0 |
12304 |
CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAIntraFnReachability) |
0 |
| 12305 |
CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAInterFnReachability) |
0 |
12305 |
CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAInterFnReachability) |
0 |
| 12306 |
|
--- |
12306 |
|
--- |
| 12307 |
CREATE_NON_RET_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAMemoryBehavior) |
0 |
12307 |
CREATE_NON_RET_ABSTRACT_ATTRIBUTE_FOR_POSITION(AAMemoryBehavior) |
0 |
| 12308 |
|
--- |
12308 |
|
--- |
| 12309 |
#undef CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION |
--- |
12309 |
#undef CREATE_FUNCTION_ONLY_ABSTRACT_ATTRIBUTE_FOR_POSITION |
--- |
| 12310 |
#undef CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION |
--- |
12310 |
#undef CREATE_FUNCTION_ABSTRACT_ATTRIBUTE_FOR_POSITION |
--- |
| 12311 |
#undef CREATE_NON_RET_ABSTRACT_ATTRIBUTE_FOR_POSITION |
--- |
12311 |
#undef CREATE_NON_RET_ABSTRACT_ATTRIBUTE_FOR_POSITION |
--- |
| 12312 |
#undef CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION |
--- |
12312 |
#undef CREATE_VALUE_ABSTRACT_ATTRIBUTE_FOR_POSITION |
--- |
| 12313 |
#undef CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION |
--- |
12313 |
#undef CREATE_ALL_ABSTRACT_ATTRIBUTE_FOR_POSITION |
--- |
| 12314 |
#undef SWITCH_PK_CREATE |
--- |
12314 |
#undef SWITCH_PK_CREATE |
--- |
| 12315 |
#undef SWITCH_PK_INV |
--- |
12315 |
#undef SWITCH_PK_INV |
--- |
| 12316 |
|
--- |
12316 |
|
--- |